From 535a603eab3f1668177f0f5065509e373e7ec47f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Schulthei=C3=9F?= <AlexanderSchultheiss@pm.me> Date: Tue, 3 May 2022 12:15:21 +0200 Subject: [PATCH] Updated benchmarking --- src/stack.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/stack.rs b/src/stack.rs index 51c3dae..5dabad7 100644 --- a/src/stack.rs +++ b/src/stack.rs @@ -109,30 +109,28 @@ mod tests { fn benchmark() { let (pushed, popped) = bench(ListStack::init()); println!( - "Own implementation took {}s for push and {} for pop.", + "Own implementation took {}ms for push and {} for pop.", pushed, popped ); - println!("Sleeping for 10 seconds."); - sleep(Duration::from_secs(10)); - let (pushed, popped) = bench(Vec::init()); println!( - "Vec wrapper took {}s for push and {} for pop.", + "Vec wrapper took {}ms for push and {} for pop.", pushed, popped ); } - fn bench<T: Stack>(mut stack: T) -> (u64, u64) { + fn bench<T: Stack>(mut stack: T) -> (u128, u128) { let start = Instant::now(); for i in 1..BENCHMARK_SIZE { stack.push_val(i); } println!("Pushed all elements"); - let pushed = start.elapsed().as_secs(); + let pushed = start.elapsed().as_millis(); + let start = Instant::now(); while stack.pop_val().is_some() {} println!("Popped all elements"); - let popped = start.elapsed().as_secs(); + let popped = start.elapsed().as_millis(); (pushed, popped) } -- GitLab