base32.rs (1903B)
1 /* 2 This file is part of TALER 3 Copyright (C) 2024, 2025, 2026 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 rand::RngExt as _; 19 use taler_common::types::base32::{Base32, decode_static, encode_static}; 20 21 fn parser(c: &mut Criterion) { 22 let mut buf = [0u8; 255]; 23 c.bench_function("base32_encode_random", |b| { 24 b.iter_batched( 25 rand::random::<[u8; 64]>, 26 |case| { 27 encode_static(&case, &mut buf); 28 }, 29 BatchSize::SmallInput, 30 ) 31 }); 32 c.bench_function("base32_decode_valid", |b| { 33 b.iter_batched( 34 || Base32::<64>::rand().to_string(), 35 |case| decode_static::<64>(case.as_bytes()).unwrap(), 36 BatchSize::SmallInput, 37 ) 38 }); 39 c.bench_function("base32_decode_random", |b| { 40 b.iter_batched( 41 || { 42 rand::rng() 43 .sample_iter::<char, _>(&rand::distr::StandardUniform) 44 .take(56) 45 .collect::<String>() 46 }, 47 |case| decode_static::<64>(case.as_bytes()).ok(), 48 BatchSize::SmallInput, 49 ) 50 }); 51 } 52 53 criterion_group!(benches, parser); 54 criterion_main!(benches);