1 | #![feature (test)] |
2 | |
3 | extern crate test; |
4 | |
5 | use std::sync::Barrier; |
6 | |
7 | use crossbeam_epoch as epoch; |
8 | use crossbeam_utils::thread::scope; |
9 | use test::Bencher; |
10 | |
11 | #[bench] |
12 | fn single_flush(b: &mut Bencher) { |
13 | const THREADS: usize = 16; |
14 | |
15 | let start = Barrier::new(THREADS + 1); |
16 | let end = Barrier::new(THREADS + 1); |
17 | |
18 | scope(|s| { |
19 | for _ in 0..THREADS { |
20 | s.spawn(|_| { |
21 | epoch::pin(); |
22 | start.wait(); |
23 | end.wait(); |
24 | }); |
25 | } |
26 | |
27 | start.wait(); |
28 | b.iter(|| epoch::pin().flush()); |
29 | end.wait(); |
30 | }) |
31 | .unwrap(); |
32 | } |
33 | |
34 | #[bench] |
35 | fn multi_flush(b: &mut Bencher) { |
36 | const THREADS: usize = 16; |
37 | const STEPS: usize = 10_000; |
38 | |
39 | b.iter(|| { |
40 | scope(|s| { |
41 | for _ in 0..THREADS { |
42 | s.spawn(|_| { |
43 | for _ in 0..STEPS { |
44 | let guard = &epoch::pin(); |
45 | guard.flush(); |
46 | } |
47 | }); |
48 | } |
49 | }) |
50 | .unwrap(); |
51 | }); |
52 | } |
53 | |