From 698f8c2f01ea549d77d7dc3338a12e04c11057b9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:02:58 +0200 Subject: Adding upstream version 1.64.0+dfsg1. Signed-off-by: Daniel Baumann --- vendor/countme/examples/bench_single_thread.rs | 77 ++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 vendor/countme/examples/bench_single_thread.rs (limited to 'vendor/countme/examples/bench_single_thread.rs') diff --git a/vendor/countme/examples/bench_single_thread.rs b/vendor/countme/examples/bench_single_thread.rs new file mode 100644 index 000000000..ac147f861 --- /dev/null +++ b/vendor/countme/examples/bench_single_thread.rs @@ -0,0 +1,77 @@ +use countme::{get, Count}; + +#[derive(Default)] +struct Foo { + _c: Count, +} + +#[derive(Default)] +struct Bar { + _c: Count, + _x: i32, +} + +mod deeply { + pub(crate) mod nested { + pub(crate) mod module { + use countme::Count; + + #[derive(Default)] + pub(crate) struct Quux { + _c: Count, + } + } + } +} + +fn main() { + countme::enable(true); + let t = std::time::Instant::now(); + let n = 6; + let m = 2_000_000; + + for _ in 0..n { + for _ in 0..m { + Foo::default(); + } + + let mut xs = Vec::with_capacity(m); + for _ in 0..m { + xs.push(Bar::default()) + } + + for _ in 0..m { + deeply::nested::module::Quux::default(); + } + + let fs = [ + || drop(Foo::default()), + || drop(Bar::default()), + || drop(deeply::nested::module::Quux::default()), + || { + #[derive(Default)] + struct Local(Count); + + Local::default(); + }, + ]; + for i in 0..m { + fs[i % 4](); + } + } + + let foo = get::(); + assert_eq!(foo.total, m * n + (m * n / 4)); + assert_eq!(foo.max_live, 1); + assert_eq!(foo.live, 0); + + let bar = get::(); + assert_eq!(bar.total, m * n + (m * n / 4)); + + // FIXME: why +1? This seems like a bug + // overreporting by 1 is not significant, but anyway + assert_eq!(bar.max_live, m + 1); + assert_eq!(bar.live, 0); + + println!("{:?}", t.elapsed()); +} -- cgit v1.2.3