iban.rs (2308B)
1 /* 2 This file is part of TALER 3 Copyright (C) 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 std::str::FromStr; 18 19 use criterion::{BatchSize, Criterion, criterion_group, criterion_main}; 20 use taler_common::types::iban::{ 21 Country::{self, *}, 22 IBAN, 23 }; 24 25 const COUNTRIES: [Country; 89] = [ 26 AD, AE, AL, AT, AZ, BA, BE, BG, BH, BI, BR, BY, CH, CR, CY, CZ, DE, DJ, DK, DO, EE, EG, ES, FI, 27 FK, FO, FR, GB, GE, GI, GL, GR, GT, HN, HR, HU, IE, IL, IQ, IS, IT, JO, KW, KZ, LB, LC, LI, LT, 28 LU, LV, LY, MC, MD, ME, MK, MN, MR, MT, MU, NI, NL, NO, OM, PK, PL, PS, PT, QA, RO, RS, RU, SA, 29 SC, SD, SE, SI, SK, SM, SO, ST, SV, TL, TN, TR, UA, VA, VG, XK, YE, 30 ]; 31 32 fn parser(c: &mut Criterion) { 33 c.bench_function("iban_random_all", |b| { 34 b.iter_batched( 35 || { 36 (0..fastrand::usize(0..40)) 37 .map(|_| fastrand::char(..)) 38 .collect::<String>() 39 }, 40 |case| IBAN::from_str(&case), 41 BatchSize::SmallInput, 42 ) 43 }); 44 c.bench_function("iban_random_alphanumeric", |b| { 45 b.iter_batched( 46 || { 47 (0..fastrand::usize(0..40)) 48 .map(|_| fastrand::alphanumeric()) 49 .collect::<String>() 50 }, 51 |case| IBAN::from_str(&case), 52 BatchSize::SmallInput, 53 ) 54 }); 55 56 c.bench_function("iban_valid", |b| { 57 b.iter_batched( 58 || IBAN::random(fastrand::choice(COUNTRIES).unwrap()).to_string(), 59 |case| IBAN::from_str(&case).unwrap(), 60 BatchSize::SmallInput, 61 ) 62 }); 63 } 64 65 criterion_group!(benches, parser); 66 criterion_main!(benches);