summaryrefslogtreecommitdiffstats
path: root/vendor/backtrace/benches/benchmarks.rs
blob: e14e733b8d0361d94416545df7b4ab655b3b0276 (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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#![feature(test)]

extern crate test;

#[cfg(feature = "std")]
use backtrace::Backtrace;

#[bench]
#[cfg(feature = "std")]
fn trace(b: &mut test::Bencher) {
    #[inline(never)]
    fn the_function() {
        backtrace::trace(|frame| {
            let ip = frame.ip();
            test::black_box(ip);
            true
        });
    }
    b.iter(the_function);
}

#[bench]
#[cfg(feature = "std")]
fn trace_and_resolve_callback(b: &mut test::Bencher) {
    #[inline(never)]
    fn the_function() {
        backtrace::trace(|frame| {
            backtrace::resolve(frame.ip(), |symbol| {
                let addr = symbol.addr();
                test::black_box(addr);
            });
            true
        });
    }
    b.iter(the_function);
}

#[bench]
#[cfg(feature = "std")]
fn trace_and_resolve_separate(b: &mut test::Bencher) {
    #[inline(never)]
    fn the_function(frames: &mut Vec<*mut std::ffi::c_void>) {
        backtrace::trace(|frame| {
            frames.push(frame.ip());
            true
        });
        frames.iter().for_each(|frame_ip| {
            backtrace::resolve(*frame_ip, |symbol| {
                test::black_box(symbol);
            });
        });
    }
    let mut frames = Vec::with_capacity(1024);
    b.iter(|| {
        the_function(&mut frames);
        frames.clear();
    });
}

#[bench]
#[cfg(feature = "std")]
fn new_unresolved(b: &mut test::Bencher) {
    #[inline(never)]
    fn the_function() {
        let bt = Backtrace::new_unresolved();
        test::black_box(bt);
    }
    b.iter(the_function);
}

#[bench]
#[cfg(feature = "std")]
fn new(b: &mut test::Bencher) {
    #[inline(never)]
    fn the_function() {
        let bt = Backtrace::new();
        test::black_box(bt);
    }
    b.iter(the_function);
}

#[bench]
#[cfg(feature = "std")]
fn new_unresolved_and_resolve_separate(b: &mut test::Bencher) {
    #[inline(never)]
    fn the_function() {
        let mut bt = Backtrace::new_unresolved();
        bt.resolve();
        test::black_box(bt);
    }
    b.iter(the_function);
}