summaryrefslogtreecommitdiffstats
path: root/third_party/rust/crossbeam-epoch/benches/defer.rs
blob: 246f907988275860b03b65fea171e1168e5a1e73 (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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#![feature(test)]

extern crate test;

use crossbeam_epoch::{self as epoch, Owned};
use crossbeam_utils::thread::scope;
use test::Bencher;

#[bench]
fn single_alloc_defer_free(b: &mut Bencher) {
    b.iter(|| {
        let guard = &epoch::pin();
        let p = Owned::new(1).into_shared(guard);
        unsafe {
            guard.defer_destroy(p);
        }
    });
}

#[bench]
fn single_defer(b: &mut Bencher) {
    b.iter(|| {
        let guard = &epoch::pin();
        guard.defer(move || ());
    });
}

#[bench]
fn multi_alloc_defer_free(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();
                        let p = Owned::new(1).into_shared(guard);
                        unsafe {
                            guard.defer_destroy(p);
                        }
                    }
                });
            }
        })
        .unwrap();
    });
}

#[bench]
fn multi_defer(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.defer(move || ());
                    }
                });
            }
        })
        .unwrap();
    });
}