Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upPerformance benchmarks #3
Comments
|
CC @pcwalton |
|
When I make the benchmark read back from the vector, a non-spilled SmallVec is faster than a Vec. Also, none of these really test memory locality and pointer indirection costs. Bigger differences should occur when a SmallVec is used as a field type in a larger structure or array. #[bench]
fn bench_normal(b: &mut Bencher) {
b.iter(|| {
for _ in 0..10000 {
let mut v = Vec::with_capacity(32);
for _ in 0..32 {
v.push(1)
}
let mut sum = 0;
for x in v {
sum += x;
}
test::black_box(sum);
}
});
}
#[bench]
fn bench_smallvec(b: &mut Bencher) {
b.iter(|| {
for _ in 0..10000 {
let mut v = SmallVec32::new();
for _ in 0..32 {
v.push(1)
}
let mut sum = 0;
for x in v.into_iter() {
sum += x;
}
test::black_box(sum);
}
});
}
|
|
Thanks for the explanation. It would be nice to have these and the field access benchmarks in the project itself, so it would be easier for people to evaluate whether this is something they need. |
nah, you should bench your use case |
|
Benchmarks now exist. |
Do you have performance benchmarks showing if a
SmallVecis actually faster than a normal vec? The benchmarks I came up with are showing thatVecis actually faster, or at least comparable.