• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // This file is part of ICU4X. For terms of use, please see the file
2 // called LICENSE at the top level of the ICU4X source tree
3 // (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).
4 
5 mod common;
6 use common::*;
7 
8 use criterion::black_box;
9 use criterion::criterion_group;
10 use criterion::criterion_main;
11 use criterion::Bencher;
12 use criterion::Criterion;
13 
14 use tinystr::TinyAsciiStr;
15 
deserialize(c: &mut Criterion)16 fn deserialize(c: &mut Criterion) {
17     macro_rules! cfs {
18         ($r:ty, $inputs:expr) => {
19             |b: &mut Bencher| {
20                 let serialized: Vec<Vec<u8>> = $inputs
21                     .iter()
22                     .map(|s| postcard::to_stdvec(&s.parse::<$r>().unwrap()).unwrap())
23                     .collect();
24                 b.iter(|| {
25                     for bytes in &serialized {
26                         let _: Result<$r, _> = black_box(postcard::from_bytes(bytes));
27                     }
28                 })
29             }
30         };
31     }
32 
33     bench_block!(c, "deserialize", cfs);
34 }
35 
36 criterion_group!(benches, deserialize,);
37 criterion_main!(benches);
38