taler-rust

GNU Taler code in Rust. Largely core banking integrations.
Log | Files | Refs | Submodules | README | LICENSE

base32.rs (1819B)


      1 /*
      2   This file is part of TALER
      3   Copyright (C) 2024-2025 Taler Systems SA
      4 
      5   TALER is free software; you can redistribute it and/or modify it under the
      6   terms of the GNU Affero General Public License as published by the Free Software
      7   Foundation; either version 3, or (at your option) any later version.
      8 
      9   TALER is distributed in the hope that it will be useful, but WITHOUT ANY
     10   WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
     11   A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more details.
     12 
     13   You should have received a copy of the GNU Affero General Public License along with
     14   TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
     15 */
     16 
     17 use criterion::{BatchSize, Criterion, criterion_group, criterion_main};
     18 use taler_common::types::base32::{Base32, decode, encode_static};
     19 
     20 fn parser(c: &mut Criterion) {
     21     let mut buf = [0u8; 255];
     22     c.bench_function("base32_encode_random", |b| {
     23         b.iter_batched(
     24             || {
     25                 let mut bytes = [0; 64];
     26                 fastrand::fill(&mut bytes);
     27                 bytes
     28             },
     29             |case| {
     30                 encode_static(&case, &mut buf);
     31             },
     32             BatchSize::SmallInput,
     33         )
     34     });
     35     c.bench_function("base32_decode_valid", |b| {
     36         b.iter_batched(
     37             || Base32::<64>::rand().to_string(),
     38             |case| decode::<64>(case.as_bytes()).unwrap(),
     39             BatchSize::SmallInput,
     40         )
     41     });
     42     c.bench_function("base32_decode_random", |b| {
     43         b.iter_batched(
     44             || (0..56).map(|_| fastrand::char(..)).collect::<String>(),
     45             |case| decode::<64>(case.as_bytes()).ok(),
     46             BatchSize::SmallInput,
     47         )
     48     });
     49 }
     50 
     51 criterion_group!(benches, parser);
     52 criterion_main!(benches);