• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 extern crate criterion;
2 extern crate thread_local;
3 
4 use criterion::{black_box, BatchSize};
5 
6 use thread_local::ThreadLocal;
7 
main()8 fn main() {
9     let mut c = criterion::Criterion::default().configure_from_args();
10 
11     c.bench_function("get", |b| {
12         let local = ThreadLocal::new();
13         local.get_or(|| Box::new(0));
14         b.iter(|| {
15             black_box(local.get());
16         });
17     });
18 
19     c.bench_function("insert", |b| {
20         b.iter_batched_ref(
21             ThreadLocal::new,
22             |local| {
23                 black_box(local.get_or(|| 0));
24             },
25             BatchSize::SmallInput,
26         )
27     });
28 }
29