Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
[package]
name = "scoped_threadpool"
version = "0.1.6"
authors = ["Marvin Löbel <[email protected]>"]
authors = ["Marvin Löbel <[email protected]>", "Popog"]
license = "MIT"
build = "build.rs"

description = "A library for scoped and cached threadpools."
readme = "README.md"
Expand All @@ -12,11 +11,8 @@ documentation = "http://kimundi.github.io/scoped-threadpool-rs/scoped_threadpool
repository = "https://github.com/Kimundi/scoped-threadpool-rs"
keywords = ["thread", "scoped", "pool", "cached", "threadpool"]

[build-dependencies]
rustc_version = "0.1"

[dev-dependencies]
lazy_static = "*"
[dependencies]
crossbeam = "0.2.4"

[features]
nightly = []
12 changes: 5 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use scoped_threadpool::Pool;

fn main() {
// Create a threadpool holding 4 threads
let mut pool = Pool::new(4);
let pool = Pool::new(4);

let mut vec = vec![0, 1, 2, 3, 4, 5, 6, 7];

Expand All @@ -41,13 +41,11 @@ fn main() {
pool.scoped(|scoped| {
// Create references to each element in the vector ...
for e in &mut vec {
// ... and add 1 to it in a seperate thread
// ... and add 1 to it in a separate thread
// (execute() is safe to call in nightly)
unsafe {
scoped.execute(move || {
*e += 1;
});
}
scoped.execute(move || {
*e += 1;
});
}
});

Expand Down
125 changes: 125 additions & 0 deletions benches/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
#![feature(test)]
#![feature(const_fn)]

extern crate test;
#[macro_use]
extern crate scoped_threadpool;

use self::test::{Bencher, black_box};
use scoped_threadpool::{Pool, Anchored};

// const MS_SLEEP_PER_OP: u32 = 1;

fn fib(n: u64) -> u64 {
let mut prev_prev: u64 = 1;
let mut prev = 1;
let mut current = 1;
for _ in 2..(n+1) {
current = prev_prev.wrapping_add(prev);
prev_prev = prev;
prev = current;
}
current
}

fn threads_interleaved_n(pool: &Pool) {
let size = 1024; // 1kiB

let mut data = vec![1u8; size];
pool.scoped(|s| {
for e in data.iter_mut() {
s.execute(move || {
*e += fib(black_box(1000 * (*e as u64))) as u8;
for i in 0..10000 { black_box(i); }
//thread::sleep_ms(MS_SLEEP_PER_OP);
});
}
});
}

#[bench]
fn threads_interleaved_1(b: &mut Bencher) {
let pool = Pool::new(1);
b.iter(|| threads_interleaved_n(&pool))
}

#[bench]
fn threads_interleaved_2(b: &mut Bencher) {
let pool = Pool::new(2);
b.iter(|| threads_interleaved_n(&pool))
}

#[bench]
fn threads_interleaved_4(b: &mut Bencher) {
let pool = Pool::new(4);
b.iter(|| threads_interleaved_n(&pool))
}

#[bench]
fn threads_interleaved_8(b: &mut Bencher) {
let pool = Pool::new(8);
b.iter(|| threads_interleaved_n(&pool))
}

fn threads_chunked_n(pool: &Pool) {
// Set this to 1GB and 40 to get good but slooow results
let size = 1024 * 1024 * 10 / 4; // 10MiB
let bb_repeat = 50;

let mut data = vec![0u32; size];
let n = pool.threads();
pool.scoped(|s| {
let l = (data.len() - 1) / n as usize + 1;
for es in data.chunks_mut(l) {
s.execute(move || {
if es.len() > 1 {
es[0] = 1;
es[1] = 1;
for i in 2..es.len() {
// Fibonnaci gets big fast,
// so just wrap around all the time
es[i] = black_box(es[i-1].wrapping_add(es[i-2]));
for i in 0..bb_repeat { black_box(i); }
}
}
//thread::sleep_ms(MS_SLEEP_PER_OP);
});
}
});
}

#[bench]
fn threads_chunked_1(b: &mut Bencher) {
let pool = Pool::new(1);
b.iter(|| threads_chunked_n(&pool))
}

#[bench]
fn threads_chunked_2(b: &mut Bencher) {
let pool = Pool::new(2);
b.iter(|| threads_chunked_n(&pool))
}

#[bench]
fn threads_chunked_3(b: &mut Bencher) {
let pool = Pool::new(3);
b.iter(|| threads_chunked_n(&pool))
}

#[bench]
fn threads_chunked_4(b: &mut Bencher) {
let pool = Pool::new(4);
b.iter(|| threads_chunked_n(&pool))
}

#[bench]
fn threads_chunked_5(b: &mut Bencher) {
let pool = Pool::new(5);
b.iter(|| threads_chunked_n(&pool))
}

#[bench]
fn threads_chunked_8(b: &mut Bencher) {
let pool = Pool::new(8);
b.iter(|| threads_chunked_n(&pool))
}
7 changes: 0 additions & 7 deletions build.rs

This file was deleted.

Loading