summaryrefslogtreecommitdiffstats
path: root/third_party/rust/crossbeam-epoch/benches/flush.rs
blob: 99aab19e1e259448a3befc87e83cc786adc44dbb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#![feature(test)]

extern crate test;

use std::sync::Barrier;

use crossbeam_epoch as epoch;
use crossbeam_utils::thread::scope;
use test::Bencher;

#[bench]
fn single_flush(b: &mut Bencher) {
    const THREADS: usize = 16;

    let start = Barrier::new(THREADS + 1);
    let end = Barrier::new(THREADS + 1);

    scope(|s| {
        for _ in 0..THREADS {
            s.spawn(|_| {
                epoch::pin();
                start.wait();
                end.wait();
            });
        }

        start.wait();
        b.iter(|| epoch::pin().flush());
        end.wait();
    })
    .unwrap();
}

#[bench]
fn multi_flush(b: &mut Bencher) {
    const THREADS: usize = 16;
    const STEPS: usize = 10_000;

    b.iter(|| {
        scope(|s| {
            for _ in 0..THREADS {
                s.spawn(|_| {
                    for _ in 0..STEPS {
                        let guard = &epoch::pin();
                        guard.flush();
                    }
                });
            }
        })
        .unwrap();
    });
}