Skip to content

Commit 5dd7b59

Browse files
committed
improve benchmarks, generated by xmacros
This adds a lot benchmarks that compares HeaderVec std Vec. Results show that we are in the same ballpark than std Vec. Also enables debug symbols for bench builds as this is quasi-required for some profilers and flamegraphs.
1 parent d168f01 commit 5dd7b59

2 files changed

Lines changed: 65 additions & 20 deletions

File tree

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,7 @@ atomic_append = []
1818

1919
[dev-dependencies]
2020
xmacro = "0.2.0"
21+
22+
# include debug info for flamgraph and other profiling tools
23+
[profile.bench]
24+
debug = true

benches/compare_std_vec.rs

Lines changed: 61 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
extern crate std;
44
extern crate test;
5+
use xmacro::xmacro;
56

67
use header_vec::*;
78
use test::Bencher;
@@ -127,11 +128,48 @@ fn test_regular_vec_create(b: &mut Bencher) {
127128
// });
128129
// }
129130

131+
xmacro! {
132+
$[
133+
benchfunc: type:
134+
hv_create_bench (HeaderVec::<(), _>)
135+
vec_create_bench (Vec)
136+
]
137+
138+
fn $benchfunc<T>(b: &mut Bencher, init: &[T])
139+
where
140+
T: Clone + Default,
141+
{
142+
b.iter(|| {
143+
let v = $type::from(init);
144+
v
145+
});
146+
}
147+
}
148+
149+
xmacro! {
150+
// benching construction times.
151+
$[
152+
bench: init:
153+
small [123; 1]
154+
middle [123; 1000]
155+
large [[123;32]; 100000]
156+
]
157+
158+
#[bench]
159+
fn $+bench_hv_create_$bench(b: &mut Bencher) {
160+
hv_create_bench(b, &$init);
161+
}
162+
163+
#[bench]
164+
fn $+bench_vec_create_$bench(b: &mut Bencher) {
165+
vec_create_bench(b, &$init);
166+
}
167+
}
168+
130169
#[cfg(feature = "std")]
131170
mod stdbench {
132171
use super::*;
133-
use std::ops::{Range, RangeBounds};
134-
use xmacro::xmacro;
172+
use std::ops::RangeBounds;
135173

136174
xmacro! {
137175
$[
@@ -156,18 +194,18 @@ mod stdbench {
156194
xmacro! {
157195
$[
158196
bench: init: range:
159-
middle [123; 1000] (100..500)
160-
begin [123; 1000] (..500)
161-
end [123; 1000] (100..)
197+
begin [123; 10000] (..5000)
198+
middle [123; 10000] (1000..5000)
199+
end [123; 10000] (1000..)
162200
]
163201

164202
#[bench]
165-
fn $+test_hv_drain_$bench(b: &mut Bencher) {
203+
fn $+bench_hv_drain_$bench(b: &mut Bencher) {
166204
hv_drain_bench(b, &$init, $range);
167205
}
168206

169207
#[bench]
170-
fn $+test_vec_drain_$bench(b: &mut Bencher) {
208+
fn $+bench_vec_drain_$bench(b: &mut Bencher) {
171209
vec_drain_bench(b, &$init, $range);
172210
}
173211
}
@@ -181,7 +219,7 @@ mod stdbench {
181219

182220
fn $benchfunc<T, R, I>(b: &mut Bencher, init: &[T], range: R, replace_with: I)
183221
where
184-
T: Clone + Default,
222+
T: Clone,
185223
R: RangeBounds<usize> + Clone,
186224
I: IntoIterator<Item = T> + Clone,
187225
{
@@ -195,25 +233,28 @@ mod stdbench {
195233

196234
xmacro! {
197235
$[
198-
bench: init: range: replace_with:
199-
nop [123; 1000] (0..0) []
200-
insert [123; 1000] (100..100) [123;500]
201-
remove [123; 1000] (100..600) []
202-
middle_shorter [123; 1000] (400..500) [234;50]
203-
middle_longer [123; 1000] (400..500) [345;200]
204-
middle_same [123; 1000] (400..500) [456;100]
205-
end_shorter [123; 1000] (900..) [234;50]
206-
end_longer [123; 1000] (900..) [345;200]
207-
end_same [123; 1000] (900..) [456;100]
236+
bench: init: range: replace_with:
237+
nop [123; 10000] (0..0) []
238+
insert [123; 10000] (1000..1000) [123; 5000]
239+
insert_big [[123;64]; 10000] (1000..1000) [[123; 64]; 5000]
240+
remove [123; 10000] (1000..6000) []
241+
middle_shorter [123; 10000] (4000..5000) [234; 500]
242+
middle_longer [123; 10000] (4000..5000) [345; 2000]
243+
middle_same [123; 10000] (4000..5000) [456; 1000]
244+
end_shorter [123; 10000] (9000..) [234; 500]
245+
end_longer [123; 10000] (9000..) [345; 2000]
246+
end_same [123; 10000] (9000..) [456; 1000]
247+
append_big [[123;64]; 10000] (10000..) [[456; 64]; 5000]
248+
append_front_big [[123;64]; 100000] (0..0) [[456; 64]; 1]
208249
]
209250

210251
#[bench]
211-
fn $+test_hv_splice_$bench(b: &mut Bencher) {
252+
fn $+bench_hv_splice_$bench(b: &mut Bencher) {
212253
hv_splice_bench(b, &$init, $range, $replace_with)
213254
}
214255

215256
#[bench]
216-
fn $+test_vec_splice_$bench(b: &mut Bencher) {
257+
fn $+bench_vec_splice_$bench(b: &mut Bencher) {
217258
vec_splice_bench(b, &$init, $range, $replace_with)
218259
}
219260
}

0 commit comments

Comments
 (0)