summaryrefslogtreecommitdiffstats
path: root/library/backtrace/benches
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
commit698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch)
tree173a775858bd501c378080a10dca74132f05bc50 /library/backtrace/benches
parentInitial commit. (diff)
downloadrustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz
rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'library/backtrace/benches')
-rw-r--r--library/backtrace/benches/benchmarks.rs92
1 files changed, 92 insertions, 0 deletions
diff --git a/library/backtrace/benches/benchmarks.rs b/library/backtrace/benches/benchmarks.rs
new file mode 100644
index 000000000..e14e733b8
--- /dev/null
+++ b/library/backtrace/benches/benchmarks.rs
@@ -0,0 +1,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);
+}