Skip to content
Snippets Groups Projects
Commit 535a603e authored by Alexander Schultheiß's avatar Alexander Schultheiß
Browse files

Updated benchmarking

parent 4fdbb59b
Branches main
No related merge requests found
......@@ -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)
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment