diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
commit | 2aa4a82499d4becd2284cdb482213d541b8804dd (patch) | |
tree | b80bf8bf13c3766139fbacc530efd0dd9d54394c /third_party/rust/tracing/benches/no_subscriber.rs | |
parent | Initial commit. (diff) | |
download | firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.tar.xz firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.zip |
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/tracing/benches/no_subscriber.rs')
-rw-r--r-- | third_party/rust/tracing/benches/no_subscriber.rs | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/third_party/rust/tracing/benches/no_subscriber.rs b/third_party/rust/tracing/benches/no_subscriber.rs new file mode 100644 index 0000000000..797f258c6b --- /dev/null +++ b/third_party/rust/tracing/benches/no_subscriber.rs @@ -0,0 +1,61 @@ +use criterion::{black_box, criterion_group, criterion_main, Criterion}; +use tracing::Level; + +fn bench_no_subscriber(c: &mut Criterion) { + use std::sync::atomic::{AtomicUsize, Ordering}; + + let mut group = c.benchmark_group("no_subscriber"); + + group.bench_function("span", |b| { + b.iter(|| { + black_box(tracing::span!(Level::TRACE, "span")); + }) + }); + group.bench_function("event", |b| { + b.iter(|| { + tracing::event!(Level::TRACE, "hello"); + }) + }); + group.bench_function("relaxed_load", |b| { + let foo = AtomicUsize::new(1); + b.iter(|| black_box(foo.load(Ordering::Relaxed))); + }); + group.bench_function("acquire_load", |b| { + let foo = AtomicUsize::new(1); + b.iter(|| black_box(foo.load(Ordering::Acquire))) + }); + group.bench_function("log", |b| { + b.iter(|| { + log::log!(log::Level::Info, "log"); + }) + }); + group.finish(); +} + +fn bench_fields(c: &mut Criterion) { + let mut group = c.benchmark_group("no_subscriber_field"); + group.bench_function("span", |b| { + b.iter(|| { + black_box(tracing::span!( + Level::TRACE, + "span", + foo = tracing::field::display(format!("bar {:?}", 2)) + )); + }) + }); + group.bench_function("event", |b| { + b.iter(|| { + tracing::event!( + Level::TRACE, + foo = tracing::field::display(format!("bar {:?}", 2)) + ); + }) + }); + group.bench_function("log", |b| { + b.iter(|| log::log!(log::Level::Trace, "{}", format!("bar {:?}", 2))) + }); + group.finish(); +} + +criterion_group!(benches, bench_no_subscriber, bench_fields); +criterion_main!(benches); |