Skip to content

Commit

Permalink
Merge pull request #106 from jimvdl/benchmark-fix
Browse files Browse the repository at this point in the history
Benchmark fix
  • Loading branch information
jonhoo committed Mar 25, 2022
2 parents f328549 + ad43335 commit 85ac469
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
10 changes: 5 additions & 5 deletions benches/flurry_dashmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Throughput};
use flurry::{epoch, HashMap};
use flurry::HashMap;
use rayon;
use rayon::prelude::*;
use std::sync::Arc;
Expand All @@ -26,7 +26,7 @@ const ITER: u64 = 32 * 1024;
fn task_insert_flurry_u64_u64_guard_every_it() -> HashMap<u64, u64> {
let map = HashMap::with_capacity(ITER as usize);
(0..ITER).into_par_iter().for_each(|i| {
let guard = epoch::pin();
let guard = map.guard();
map.insert(i, i + 7, &guard);
});
map
Expand Down Expand Up @@ -63,7 +63,7 @@ fn task_insert_flurry_u64_u64_guard_once(threads: usize) -> HashMap<u64, u64> {
let m = map.clone();
s.spawn(move |_| {
let start = t * inc;
let guard = epoch::pin();
let guard = m.guard();
for i in start..(start + inc) {
m.insert(i, i + 7, &guard);
}
Expand Down Expand Up @@ -97,7 +97,7 @@ fn insert_flurry_u64_u64_guard_once(c: &mut Criterion) {

fn task_get_flurry_u64_u64_guard_every_it(map: &HashMap<u64, u64>) {
(0..ITER).into_par_iter().for_each(|i| {
let guard = epoch::pin();
let guard = map.guard();
assert_eq!(*map.get(&i, &guard).unwrap(), i + 7);
});
}
Expand Down Expand Up @@ -134,7 +134,7 @@ fn task_get_flurry_u64_u64_guard_once(threads: usize, map: Arc<HashMap<u64, u64>
let m = map.clone();
s.spawn(move |_| {
let start = t * inc;
let guard = epoch::pin();
let guard = m.guard();
for i in start..(start + inc) {
if let Some(&v) = m.get(&i, &guard) {
assert_eq!(v, i + 7);
Expand Down
21 changes: 11 additions & 10 deletions benches/flurry_hashbrown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/

use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion, Throughput};
use flurry::{epoch, HashMap};
use flurry::HashMap;

const SIZE: usize = 1000;

Expand Down Expand Up @@ -53,7 +53,7 @@ macro_rules! bench_insert {
$group.bench_function(BenchmarkId::from_parameter($bench_id), |b| {
let map: HashMap<_, _> = HashMap::with_capacity(SIZE as usize);
b.iter(|| {
let guard = epoch::pin();
let guard = map.guard();
map.clear(&guard);
($keydist).take(SIZE).for_each(|i| {
map.insert(i, i, &guard);
Expand All @@ -77,7 +77,7 @@ macro_rules! bench_insert_erase {
// NOTE: in testing, I tried running this without the local scope.
// not dropping the guard and pinning the epoch for the entire benchmark literally
// crashed multiple programs on my PC, so I advise not to do that...
let guard = epoch::pin();
let guard = base.guard();
($keydist).take(SIZE).for_each(|i| {
base.insert(i, i, &guard);
});
Expand All @@ -92,14 +92,15 @@ macro_rules! bench_insert_erase {

// While keeping the size constant,
// replace the first keydist with the second.
let guard = epoch::pin();
let guard = map.guard();
(&mut add_iter)
.zip(&mut remove_iter)
.take(SIZE)
.for_each(|(add, remove)| {
map.insert(add, add, &guard);
black_box(map.remove(&remove, &guard));
});
drop(guard);
black_box(&mut map);
});
});
Expand All @@ -117,15 +118,15 @@ macro_rules! bench_lookup {
let map: HashMap<_, _> = HashMap::with_capacity(SIZE as usize);
{
// see bench_insert_erase for a comment on the local scope
let guard = epoch::pin();
let guard = map.guard();
($keydist).take(SIZE).for_each(|i| {
map.insert(i, i, &guard);
});
}

$group.bench_function(BenchmarkId::from_parameter($bench_id), |b| {
b.iter(|| {
let guard = epoch::pin();
let guard = map.guard();
($keydist).take(SIZE).for_each(|i| {
black_box(map.get(&i, &guard));
});
Expand All @@ -142,15 +143,15 @@ macro_rules! bench_lookup_fail {
let mut iter = $keydist;
{
// see bench_insert_erase for a comment on the local scope
let guard = epoch::pin();
let guard = map.guard();
(&mut iter).take(SIZE).for_each(|i| {
map.insert(i, i, &guard);
});
}

$group.bench_function(BenchmarkId::from_parameter($bench_id), |b| {
b.iter(|| {
let guard = epoch::pin();
let guard = map.guard();
(&mut iter).take(SIZE).for_each(|i| {
black_box(map.get(&i, &guard));
});
Expand All @@ -170,15 +171,15 @@ macro_rules! bench_iter {
let map: HashMap<_, _> = HashMap::with_capacity(SIZE as usize);
{
// see bench_insert_erase for a comment on the local scope
let guard = epoch::pin();
let guard = map.guard();
($keydist).take(SIZE).for_each(|i| {
map.insert(i, i, &guard);
});
}

$group.bench_function(BenchmarkId::from_parameter($bench_id), |b| {
b.iter(|| {
let guard = epoch::pin();
let guard = map.guard();
for k in map.iter(&guard) {
black_box(k);
}
Expand Down

0 comments on commit 85ac469

Please sign in to comment.