fn insert_remove_local(c: &mut Criterion) { // the 10000-insertion benchmark takes the `slab` crate about an hour to // run; don't run this unless you're prepared for that... // const N_INSERTIONS: &'static [usize] = &[100, 500, 1000, 5000, 10000]; letmut group = c.benchmark_group("insert_remove_local"); let g = group.measurement_time(Duration::from_secs(15));
for i in N_INSERTIONS {
g.bench_with_input(BenchmarkId::new("sharded_slab", i), i, |b, &i| {
b.iter_custom(|iters| { letmut total = Duration::from_secs(0); for _ in0..iters { let bench = MultithreadedBench::new(Arc::new(sharded_slab::Slab::new())); let elapsed = bench
.thread(move |start, slab| {
start.wait(); let v: Vec<_> = (0..i).map(|i| slab.insert(i).unwrap()).collect(); for i in v {
slab.remove(i);
}
})
.thread(move |start, slab| {
start.wait(); let v: Vec<_> = (0..i).map(|i| slab.insert(i).unwrap()).collect(); for i in v {
slab.remove(i);
}
})
.thread(move |start, slab| {
start.wait(); let v: Vec<_> = (0..i).map(|i| slab.insert(i).unwrap()).collect(); for i in v {
slab.remove(i);
}
})
.thread(move |start, slab| {
start.wait(); let v: Vec<_> = (0..i).map(|i| slab.insert(i).unwrap()).collect(); for i in v {
slab.remove(i);
}
})
.run();
total += elapsed;
}
total
})
});
g.bench_with_input(BenchmarkId::new("slab_biglock", i), i, |b, &i| {
b.iter_custom(|iters| { letmut total = Duration::from_secs(0); let i = i; for _ in0..iters { let bench = MultithreadedBench::new(Arc::new(RwLock::new(slab::Slab::new()))); let elapsed = bench
.thread(move |start, slab| {
start.wait(); let v: Vec<_> =
(0..i).map(|i| slab.write().unwrap().insert(i)).collect(); for i in v {
slab.write().unwrap().remove(i);
}
})
.thread(move |start, slab| {
start.wait(); let v: Vec<_> =
(0..i).map(|i| slab.write().unwrap().insert(i)).collect(); for i in v {
slab.write().unwrap().remove(i);
}
})
.thread(move |start, slab| {
start.wait(); let v: Vec<_> =
(0..i).map(|i| slab.write().unwrap().insert(i)).collect(); for i in v {
slab.write().unwrap().remove(i);
}
})
.thread(move |start, slab| {
start.wait(); let v: Vec<_> =
(0..i).map(|i| slab.write().unwrap().insert(i)).collect(); for i in v {
slab.write().unwrap().remove(i);
}
})
.run();
total += elapsed;
}
total
})
});
}
group.finish();
}
fn insert_remove_single_thread(c: &mut Criterion) { // the 10000-insertion benchmark takes the `slab` crate about an hour to // run; don't run this unless you're prepared for that... // const N_INSERTIONS: &'static [usize] = &[100, 500, 1000, 5000, 10000]; letmut group = c.benchmark_group("insert_remove_single_threaded");
for i in N_INSERTIONS {
group.bench_with_input(BenchmarkId::new("sharded_slab", i), i, |b, &i| { let slab = sharded_slab::Slab::new();
b.iter(|| { let v: Vec<_> = (0..i).map(|i| slab.insert(i).unwrap()).collect(); for i in v {
slab.remove(i);
}
});
});
group.bench_with_input(BenchmarkId::new("slab_no_lock", i), i, |b, &i| { letmut slab = slab::Slab::new();
b.iter(|| { let v: Vec<_> = (0..i).map(|i| slab.insert(i)).collect(); for i in v {
slab.remove(i);
}
});
});
group.bench_with_input(BenchmarkId::new("slab_uncontended", i), i, |b, &i| { let slab = RwLock::new(slab::Slab::new());
b.iter(|| { let v: Vec<_> = (0..i).map(|i| slab.write().unwrap().insert(i)).collect(); for i in v {
slab.write().unwrap().remove(i);
}
});
});
}
group.finish();
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.