1 | #![feature (test)] |
2 | |
3 | extern crate test; |
4 | |
5 | use crossbeam_epoch::{self as epoch, Owned}; |
6 | use crossbeam_utils::thread::scope; |
7 | use test::Bencher; |
8 | |
9 | #[bench] |
10 | fn single_alloc_defer_free(b: &mut Bencher) { |
11 | b.iter(|| { |
12 | let guard = &epoch::pin(); |
13 | let p = Owned::new(1).into_shared(guard); |
14 | unsafe { |
15 | guard.defer_destroy(p); |
16 | } |
17 | }); |
18 | } |
19 | |
20 | #[bench] |
21 | fn single_defer(b: &mut Bencher) { |
22 | b.iter(|| { |
23 | let guard = &epoch::pin(); |
24 | guard.defer(move || ()); |
25 | }); |
26 | } |
27 | |
28 | #[bench] |
29 | fn multi_alloc_defer_free(b: &mut Bencher) { |
30 | const THREADS: usize = 16; |
31 | const STEPS: usize = 10_000; |
32 | |
33 | b.iter(|| { |
34 | scope(|s| { |
35 | for _ in 0..THREADS { |
36 | s.spawn(|_| { |
37 | for _ in 0..STEPS { |
38 | let guard = &epoch::pin(); |
39 | let p = Owned::new(1).into_shared(guard); |
40 | unsafe { |
41 | guard.defer_destroy(p); |
42 | } |
43 | } |
44 | }); |
45 | } |
46 | }) |
47 | .unwrap(); |
48 | }); |
49 | } |
50 | |
51 | #[bench] |
52 | fn multi_defer(b: &mut Bencher) { |
53 | const THREADS: usize = 16; |
54 | const STEPS: usize = 10_000; |
55 | |
56 | b.iter(|| { |
57 | scope(|s| { |
58 | for _ in 0..THREADS { |
59 | s.spawn(|_| { |
60 | for _ in 0..STEPS { |
61 | let guard = &epoch::pin(); |
62 | guard.defer(move || ()); |
63 | } |
64 | }); |
65 | } |
66 | }) |
67 | .unwrap(); |
68 | }); |
69 | } |
70 | |