Skip to content

Commit

Permalink
Add list benchmarks.
Browse files Browse the repository at this point in the history
We need to update the plot scripts, since crossbeam does not have a
list.
  • Loading branch information
Martin Hafskjold Thoresen committed Dec 6, 2017
1 parent 66e1bba commit 30e5732
Show file tree
Hide file tree
Showing 7 changed files with 136 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ lazy_static = "*"
bench = { path = './bench' }
crossbeam = "*"
bencher = "*"
rand = "*"

[dev-dependencies]
rand = "*"
time = "*"

[profile.bench]
Expand Down
3 changes: 2 additions & 1 deletion benches/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ macro_rules! run {
}
}

pub const NUM_ELEMENTS: usize = 256 * 256 * 4;
pub const NUM_ELEMENTS: usize = 256 * 256;
pub const NUM_ELEMENTS_SMALLER: usize = 256 * 4;
63 changes: 62 additions & 1 deletion benches/ebr.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
extern crate comere;
extern crate bench;
extern crate rand;
#[macro_use]
extern crate lazy_static;


#[macro_use]
mod common;
Expand All @@ -10,6 +14,9 @@ use std::thread;

use comere::ebr;
use comere::ebr::queue::Queue;
use comere::ebr::list::List;

use rand::Rng;

fn queue_push(num_threads: usize) -> bench::BenchStats {
struct State {
Expand Down Expand Up @@ -90,6 +97,54 @@ fn queue_transfer(num_threads: usize) -> bench::BenchStats {
b.into_stats()
}

fn list_remove(num_threads: usize) -> bench::BenchStats {
struct State {
list: List<u32>,
num_threads: usize,
}

use std::sync::atomic::{AtomicUsize, Ordering};
use std::cell::RefCell;
lazy_static! {
static ref THREAD_COUNTER: AtomicUsize = { AtomicUsize::new(0) };
}

thread_local! {
static THREAD_ID: RefCell<usize> = {
RefCell::new(THREAD_COUNTER.fetch_add(1, Ordering::SeqCst))
}
}

let state = State {
list: List::new(),
num_threads,
};

fn remove(state: &State) {
let ti = THREAD_ID.with(|t| *t.borrow());
for i in 0..NUM_ELEMENTS_SMALLER / state.num_threads {
let n = (i * state.num_threads + ti) as u32;
let ret = ebr::pin(|pin| state.list.remove(&n, pin));
assert!(ret.is_some());
}
}

let mut b = bench::ThreadBencher::<State, thread::JoinHandle<()>>::new(state, num_threads);
b.before(|state| {
let mut rng = rand::thread_rng();
let mut n: Vec<u32> = (0..NUM_ELEMENTS_SMALLER as u32).collect();
rng.shuffle(&mut n);
ebr::pin(|pin| {
for &i in &n {
state.list.insert(i, pin);
}
});
});

b.thread_bench(remove);
b.into_stats()
}

fn nop(num_threads: usize) -> bench::BenchStats {
#[inline(never)]
fn nop(_s: &()) {}
Expand All @@ -107,7 +162,13 @@ fn main() {

let gnuplot_output = args.get(2);

let stats = run!(num_threads, nop, queue_push, queue_pop, queue_transfer);
let stats = run!(num_threads,
nop,
list_remove,
queue_push,
queue_pop,
queue_transfer
);

println!("EBR");
println!("name;{}", bench::BenchStats::csv_header());
Expand Down
65 changes: 60 additions & 5 deletions benches/hp.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
extern crate comere;
extern crate bench;
extern crate rand;
#[macro_use]
extern crate lazy_static;

#[macro_use]
mod common;
Expand All @@ -9,6 +12,9 @@ use std::env;

use comere::hp;
use comere::hp::queue::Queue;
use comere::hp::list::List;

use rand::Rng;

fn queue_push(num_threads: usize) -> bench::BenchStats {
struct State {
Expand Down Expand Up @@ -83,6 +89,52 @@ fn queue_transfer(num_threads: usize) -> bench::BenchStats {
b.into_stats()
}

fn list_remove(num_threads: usize) -> bench::BenchStats {
struct State {
list: List<u32>,
num_threads: usize,
}

use std::sync::atomic::{AtomicUsize, Ordering};
use std::cell::RefCell;
lazy_static! {
static ref THREAD_COUNTER: AtomicUsize = { AtomicUsize::new(0) };
}

thread_local! {
static THREAD_ID: RefCell<usize> = {
RefCell::new(THREAD_COUNTER.fetch_add(1, Ordering::SeqCst))
}
}

let state = State {
list: List::new(),
num_threads,
};

fn remove(state: &State) {
let ti = THREAD_ID.with(|t| *t.borrow());
for i in 0..NUM_ELEMENTS_SMALLER / state.num_threads {
let n = (i * state.num_threads + ti) as u32;
let ret = state.list.remove(&n);
assert!(ret.is_some());
}
}

let mut b = bench::ThreadBencher::<State, hp::JoinHandle<()>>::new(state, num_threads);
b.before(|state| {
let mut rng = rand::thread_rng();
let mut n: Vec<u32> = (0..NUM_ELEMENTS_SMALLER as u32).collect();
rng.shuffle(&mut n);
for &i in &n {
state.list.insert(i);
}
});

b.thread_bench(remove);
b.into_stats()
}

fn nop(num_threads: usize) -> bench::BenchStats {
#[inline(never)]
fn nop(_s: &()) {}
Expand All @@ -93,14 +145,17 @@ fn nop(num_threads: usize) -> bench::BenchStats {

fn main() {
let args = env::args().collect::<Vec<_>>();
let num_threads: usize = args.get(1)
.ok_or(())
.and_then(|s| s.parse().map_err(|_| ()))
.unwrap_or(4);
let num_threads: usize = args.get(1).and_then(|s| s.parse().ok()).unwrap_or(4);

let gnuplot_output = args.get(2);

let stats: Vec<_> = run!(num_threads, nop, queue_push, queue_pop, queue_transfer);
let stats: Vec<_> = run!(num_threads,
nop,
list_remove,
queue_push,
queue_pop,
queue_transfer
);

println!("HP");
println!("name;{}", bench::BenchStats::csv_header());
Expand Down
9 changes: 8 additions & 1 deletion plots/box.gp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,14 @@ set size square

set pointsize 0.3

set xtics ('Crossbeam' 1, 'EBR' 2, 'HP' 3, 'HP-Spin' 4)
if (cols == 3) {
set xtics ('EBR' 1, 'HP' 2, 'HP-Spin' 3)
}

if (cols == 4) {
set xtics ('Crossbeam' 1, 'EBR' 2, 'HP' 3, 'HP-Spin' 4)
}


set terminal pdf size 10cm,10cm
set title title
Expand Down
1 change: 1 addition & 0 deletions plots/generate-plots.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ for n in $(echo "$THREADS"); do
gnuplot -e "data='col-2'; cols=4; title='Queue::Push, t=$n'; output='queue-push-$n.pdf'" box.gp
gnuplot -e "data='col-3'; cols=4; title='Queue::Pop, t=$n'; output='queue-pop-$n.pdf'" box.gp
gnuplot -e "data='col-4'; cols=4; title='Queue::Transfer, t=$n'; output='queue-transfer-$n.pdf'" box.gp
gnuplot -e "data='col-5'; cols=3; title='List::Remove, t=$n'; output='list-remove-$n.pdf'" box.gp
done
2 changes: 2 additions & 0 deletions plots/gnuplot-merge.awk
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
b[FNR] = b[FNR]" "$2;
c[FNR] = c[FNR]" "$3;
d[FNR] = d[FNR]" "$4;
e[FNR] = e[FNR]" "$5;
}

END {
for (i in a) { printf("%s\n", a[i]) > "col-1"; }
for (i in b) { printf("%s\n", b[i]) > "col-2"; }
for (i in c) { printf("%s\n", c[i]) > "col-3"; }
for (i in d) { printf("%s\n", d[i]) > "col-4"; }
for (i in e) { printf("%s\n", e[i]) > "col-5"; }
}

0 comments on commit 30e5732

Please sign in to comment.