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