Last active
November 24, 2023 19:44
-
-
Save lukas-code/c97bd707d074c4cc31f241edbc7fd2a2 to your computer and use it in GitHub Desktop.
VecDeque::drain destructor benchmark
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// criterion = "0.5" | |
use std::collections::VecDeque; | |
use std::iter; | |
use std::rc::Rc; | |
use criterion::{Criterion, black_box}; | |
fn bench_method1(c: &mut Criterion) { | |
let v = VecDeque::from_iter(0..512); | |
c.bench_function("single", |b| { | |
b.iter_batched( | |
|| v.clone(), | |
|mut v| { | |
v.drain(256..=256); | |
v | |
}, | |
criterion::BatchSize::LargeInput, | |
); | |
}); | |
c.bench_function("middle", |b| { | |
b.iter_batched( | |
|| v.clone(), | |
|mut v| { | |
v.drain(128..384); | |
v | |
}, | |
criterion::BatchSize::LargeInput, | |
); | |
}); | |
c.bench_function("front", |b| { | |
b.iter_batched( | |
|| v.clone(), | |
|mut v| { | |
v.drain(..256); | |
v | |
}, | |
criterion::BatchSize::LargeInput, | |
); | |
}); | |
c.bench_function("back", |b| { | |
b.iter_batched( | |
|| v.clone(), | |
|mut v| { | |
v.drain(256..); | |
v | |
}, | |
criterion::BatchSize::LargeInput, | |
); | |
}); | |
c.bench_function("front blackboxed", |b| { | |
b.iter_batched( | |
|| v.clone(), | |
|mut v| { | |
v.drain(black_box(0)..256); | |
v | |
}, | |
criterion::BatchSize::LargeInput, | |
); | |
}); | |
c.bench_function("back blackboxed", |b| { | |
b.iter_batched( | |
|| v.clone(), | |
|mut v| { | |
v.drain(256..black_box(512)); | |
v | |
}, | |
criterion::BatchSize::LargeInput, | |
); | |
}); | |
c.bench_function("noop", |b| { | |
b.iter_batched( | |
|| v.clone(), | |
|v| { | |
v | |
}, | |
criterion::BatchSize::LargeInput, | |
); | |
}); | |
c.bench_function("loop front", |b| { | |
b.iter_batched( | |
|| v.clone(), | |
|mut v| { | |
while v.len() >= 4 { | |
v.drain(..4); | |
black_box(&mut v); | |
} | |
}, | |
criterion::BatchSize::LargeInput, | |
); | |
}); | |
c.bench_function("loop middle", |b| { | |
b.iter_batched( | |
|| v.clone(), | |
|mut v| { | |
while v.len() >= 8 { | |
v.drain(v.len() / 2 - 4..v.len() / 2 + 4); | |
black_box(&mut v); | |
} | |
}, | |
criterion::BatchSize::LargeInput, | |
); | |
}); | |
let has_destructor = Rc::new(42); | |
let v = VecDeque::from_iter(iter::repeat_with(|| has_destructor.clone()).take(512)); | |
c.bench_function("with destructor", |b| { | |
b.iter_batched( | |
|| v.clone(), | |
|mut v| { | |
v.drain(..256); | |
v | |
}, | |
criterion::BatchSize::LargeInput, | |
); | |
}); | |
} | |
criterion::criterion_group!(benches, bench_method1); | |
criterion::criterion_main!(benches); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
single time: [27.201 ns 27.364 ns 27.520 ns] | |
change: [+3.3129% +5.0013% +6.7602%] (p = 0.00 < 0.05) | |
Performance has regressed. | |
Found 9 outliers among 100 measurements (9.00%) | |
2 (2.00%) low severe | |
3 (3.00%) low mild | |
1 (1.00%) high mild | |
3 (3.00%) high severe | |
middle time: [30.346 ns 30.727 ns 31.064 ns] | |
change: [-3.0489% -0.4959% +1.9250%] (p = 0.69 > 0.05) | |
No change in performance detected. | |
Found 14 outliers among 100 measurements (14.00%) | |
7 (7.00%) low severe | |
2 (2.00%) low mild | |
5 (5.00%) high mild | |
front time: [11.366 ns 11.456 ns 11.549 ns] | |
change: [+228.92% +270.94% +312.89%] (p = 0.00 < 0.05) | |
Performance has regressed. | |
Found 6 outliers among 100 measurements (6.00%) | |
1 (1.00%) high mild | |
5 (5.00%) high severe | |
back time: [18.106 ns 18.185 ns 18.278 ns] | |
change: [+516.15% +609.16% +701.83%] (p = 0.00 < 0.05) | |
Performance has regressed. | |
Found 5 outliers among 100 measurements (5.00%) | |
1 (1.00%) high mild | |
4 (4.00%) high severe | |
front blackboxed time: [17.104 ns 17.157 ns 17.220 ns] | |
change: [+17.880% +21.546% +24.889%] (p = 0.00 < 0.05) | |
Performance has regressed. | |
Found 8 outliers among 100 measurements (8.00%) | |
3 (3.00%) high mild | |
5 (5.00%) high severe | |
back blackboxed time: [17.904 ns 18.079 ns 18.288 ns] | |
change: [+38.290% +42.925% +47.105%] (p = 0.00 < 0.05) | |
Performance has regressed. | |
Found 10 outliers among 100 measurements (10.00%) | |
5 (5.00%) high mild | |
5 (5.00%) high severe | |
noop time: [3.2408 ns 3.3306 ns 3.4302 ns] | |
change: [-14.953% -5.8529% +3.7180%] (p = 0.27 > 0.05) | |
No change in performance detected. | |
Found 7 outliers among 100 measurements (7.00%) | |
1 (1.00%) low mild | |
2 (2.00%) high mild | |
4 (4.00%) high severe | |
loop front time: [614.81 ns 631.30 ns 650.10 ns] | |
change: [+312.32% +323.31% +336.37%] (p = 0.00 < 0.05) | |
Performance has regressed. | |
Found 4 outliers among 100 measurements (4.00%) | |
4 (4.00%) high mild | |
loop middle time: [845.83 ns 851.66 ns 858.01 ns] | |
change: [+17.500% +20.291% +23.042%] (p = 0.00 < 0.05) | |
Performance has regressed. | |
Found 18 outliers among 100 measurements (18.00%) | |
9 (9.00%) high mild | |
9 (9.00%) high severe | |
with destructor time: [356.03 ns 356.27 ns 356.52 ns] | |
change: [-2.0927% -1.1147% -0.2067%] (p = 0.02 < 0.05) | |
Change within noise threshold. | |
Found 12 outliers among 100 measurements (12.00%) | |
4 (4.00%) high mild | |
8 (8.00%) high severe |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
single time: [26.259 ns 26.539 ns 26.791 ns] | |
change: [-8.8511% -7.2264% -5.6593%] (p = 0.00 < 0.05) | |
Performance has improved. | |
Found 2 outliers among 100 measurements (2.00%) | |
1 (1.00%) high mild | |
1 (1.00%) high severe | |
middle time: [30.707 ns 31.108 ns 31.463 ns] | |
change: [+0.2810% +2.6158% +5.0190%] (p = 0.03 < 0.05) | |
Change within noise threshold. | |
Found 9 outliers among 100 measurements (9.00%) | |
4 (4.00%) low severe | |
5 (5.00%) low mild | |
front time: [2.5052 ns 2.5367 ns 2.5767 ns] | |
change: [-76.020% -73.459% -69.736%] (p = 0.00 < 0.05) | |
Performance has improved. | |
Found 9 outliers among 100 measurements (9.00%) | |
3 (3.00%) high mild | |
6 (6.00%) high severe | |
back time: [2.0339 ns 2.0819 ns 2.1351 ns] | |
change: [-87.187% -85.616% -83.262%] (p = 0.00 < 0.05) | |
Performance has improved. | |
Found 9 outliers among 100 measurements (9.00%) | |
2 (2.00%) high mild | |
7 (7.00%) high severe | |
front blackboxed time: [13.892 ns 13.983 ns 14.092 ns] | |
change: [-20.664% -18.300% -15.918%] (p = 0.00 < 0.05) | |
Performance has improved. | |
Found 13 outliers among 100 measurements (13.00%) | |
6 (6.00%) high mild | |
7 (7.00%) high severe | |
back blackboxed time: [12.278 ns 12.338 ns 12.406 ns] | |
change: [-30.817% -28.591% -26.533%] (p = 0.00 < 0.05) | |
Performance has improved. | |
Found 5 outliers among 100 measurements (5.00%) | |
2 (2.00%) high mild | |
3 (3.00%) high severe | |
noop time: [3.4973 ns 3.5853 ns 3.6758 ns] | |
change: [-6.2361% +3.4409% +14.771%] (p = 0.53 > 0.05) | |
No change in performance detected. | |
Found 5 outliers among 100 measurements (5.00%) | |
5 (5.00%) high severe | |
loop front time: [148.86 ns 149.48 ns 150.34 ns] | |
change: [-73.821% -73.588% -73.356%] (p = 0.00 < 0.05) | |
Performance has improved. | |
Found 14 outliers among 100 measurements (14.00%) | |
5 (5.00%) high mild | |
9 (9.00%) high severe | |
loop middle time: [740.77 ns 743.88 ns 747.16 ns] | |
change: [-11.650% -11.302% -10.958%] (p = 0.00 < 0.05) | |
Performance has improved. | |
Found 8 outliers among 100 measurements (8.00%) | |
6 (6.00%) high mild | |
2 (2.00%) high severe | |
with destructor time: [355.37 ns 355.84 ns 356.30 ns] | |
change: [+0.7229% +1.6541% +2.6818%] (p = 0.00 < 0.05) | |
Change within noise threshold. | |
Found 15 outliers among 100 measurements (15.00%) | |
1 (1.00%) high mild | |
14 (14.00%) high severe |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment