-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
121 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,106 +1,101 @@ | ||
#![feature(test)] | ||
extern crate test; | ||
|
||
#[cfg(all(nightly, test))] | ||
mod bench { | ||
#![cfg(nightly)] | ||
extern crate test; | ||
use self::test::Bencher; | ||
use std::sync::mpsc::channel; | ||
|
||
use self::test::Bencher; | ||
use std::sync::mpsc::channel; | ||
use std::sync::Arc; | ||
use mco::chan; | ||
|
||
use mco::chan; | ||
use mco::std::queue::mpmc_bounded::Queue; | ||
use std::thread; | ||
use std::thread; | ||
use mco::std::queue::mpsc_list::Queue; | ||
|
||
#[bench] | ||
fn bounded_mpmc(b: &mut Bencher) { | ||
b.iter(|| { | ||
let total_work = 1000_000; | ||
let nthreads = 1; | ||
let nmsgs = total_work / nthreads; | ||
let q = Queue::with_capacity(nthreads * nmsgs); | ||
assert_eq!(None, q.pop()); | ||
let (tx, rx) = chan!(); | ||
#[bench] | ||
fn bounded_mpmc(b: &mut Bencher) { | ||
b.iter(|| { | ||
let total_work = 1000_000; | ||
let nthreads = 1; | ||
let nmsgs = total_work / nthreads; | ||
let q = Queue::with_capacity(nthreads * nmsgs); | ||
assert_eq!(None, q.pop()); | ||
let (tx, rx) = chan!(); | ||
|
||
for _ in 0..nthreads { | ||
let q = q.clone(); | ||
let tx = tx.clone(); | ||
thread::spawn(move || { | ||
let q = q; | ||
for i in 0..nmsgs { | ||
assert!(q.push(i).is_ok()); | ||
} | ||
tx.send(()).unwrap(); | ||
}); | ||
} | ||
for _ in 0..nthreads { | ||
let q = q.clone(); | ||
let tx = tx.clone(); | ||
thread::spawn(move || { | ||
let q = q; | ||
for i in 0..nmsgs { | ||
assert!(q.push(i).is_ok()); | ||
} | ||
tx.send(()).unwrap(); | ||
}); | ||
} | ||
|
||
let mut completion_rxs = vec![]; | ||
for _ in 0..nthreads { | ||
let (tx, rx) = channel(); | ||
completion_rxs.push(rx); | ||
let q = q.clone(); | ||
thread::spawn(move || { | ||
let q = q; | ||
let mut i = 0; | ||
loop { | ||
match q.pop() { | ||
None => {} | ||
Some(_) => { | ||
i += 1; | ||
if i == nmsgs { | ||
break; | ||
} | ||
let mut completion_rxs = vec![]; | ||
for _ in 0..nthreads { | ||
let (tx, rx) = channel(); | ||
completion_rxs.push(rx); | ||
let q = q.clone(); | ||
thread::spawn(move || { | ||
let q = q; | ||
let mut i = 0; | ||
loop { | ||
match q.pop() { | ||
None => {} | ||
Some(_) => { | ||
i += 1; | ||
if i == nmsgs { | ||
break; | ||
} | ||
} | ||
} | ||
tx.send(i).unwrap(); | ||
}); | ||
} | ||
|
||
for rx in completion_rxs.iter_mut() { | ||
assert_eq!(nmsgs, rx.recv().unwrap()); | ||
} | ||
for _ in 0..nthreads { | ||
rx.recv().unwrap(); | ||
} | ||
}); | ||
} | ||
|
||
// #[bench] | ||
// the channel bench result show that it's 10 fold slow than our queue | ||
// not to mention the multi core contention | ||
#[allow(dead_code)] | ||
fn sys_stream_test(b: &mut Bencher) { | ||
b.iter(|| { | ||
let (tx, rx) = channel(); | ||
let total_work: usize = 1000_000; | ||
// create worker threads that generate mono increasing index | ||
// in other thread the value should be still 100 | ||
thread::spawn(move || { | ||
for i in 0..total_work { | ||
tx.send(i).unwrap(); | ||
} | ||
tx.send(i).unwrap(); | ||
}); | ||
} | ||
|
||
for rx in completion_rxs.iter_mut() { | ||
assert_eq!(nmsgs, rx.recv().unwrap()); | ||
} | ||
for _ in 0..nthreads { | ||
rx.recv().unwrap(); | ||
} | ||
}); | ||
} | ||
|
||
// #[bench] | ||
// the channel bench result show that it's 10 fold slow than our queue | ||
// not to mention the multi core contention | ||
#[allow(dead_code)] | ||
fn sys_stream_test(b: &mut Bencher) { | ||
b.iter(|| { | ||
let (tx, rx) = channel(); | ||
let total_work: usize = 1000_000; | ||
// create worker threads that generate mono increasing index | ||
// in other thread the value should be still 100 | ||
thread::spawn(move || { | ||
for i in 0..total_work { | ||
assert_eq!(i, rx.recv().unwrap()); | ||
tx.send(i).unwrap(); | ||
} | ||
}); | ||
} | ||
|
||
// improve performance from 39,294 ns/iter to 12,207 ns/iter (my computer) | ||
//test bench_channel ... bench: 12,207 ns/iter (+/- 118) | ||
#[bench] | ||
fn bench_channel(b: &mut Bencher) { | ||
b.iter(|| { | ||
let (s, r) = chan!(); | ||
for _ in 0..1000 { | ||
s.send(1); | ||
} | ||
for _ in 0..1000 { | ||
let r = r.recv().unwrap(); | ||
} | ||
}); | ||
} | ||
for i in 0..total_work { | ||
assert_eq!(i, rx.recv().unwrap()); | ||
} | ||
}); | ||
} | ||
|
||
// improve performance from 39,294 ns/iter to 12,207 ns/iter (my computer) | ||
//test bench_channel ... bench: 12,207 ns/iter (+/- 118) | ||
#[bench] | ||
fn bench_channel(b: &mut Bencher) { | ||
b.iter(|| { | ||
let (s, r) = chan!(); | ||
for _ in 0..1000 { | ||
s.send(1); | ||
} | ||
for _ in 0..1000 { | ||
let r = r.recv().unwrap(); | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#![feature(test)] | ||
extern crate test; | ||
|
||
use test::Bencher; | ||
use mco_gen::Stack; | ||
|
||
//windows 2404 ns/iter (+/- 306) | ||
#[bench] | ||
fn bench_stack_new(b: &mut Bencher) { | ||
b.iter(|| { | ||
let s = Stack::new(4096); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,26 @@ | ||
#![feature(test)] | ||
extern crate test; | ||
|
||
#[cfg(all(nightly, test))] | ||
mod bench { | ||
#![feature(test)] | ||
extern crate test; | ||
use mco::std::sync::WaitGroup; | ||
use mco::std::time::time::Time; | ||
use test::Bencher; | ||
|
||
use mco::std::sync::WaitGroup; | ||
use mco::std::time::time::Time; | ||
use test::Bencher; | ||
|
||
//test bench::single_thread_test ... bench: 44 ns/iter (+/- 1) | ||
#[bench] | ||
fn single_thread_test(b: &mut Bencher) { | ||
b.iter(|| { | ||
let now = Time::now(); | ||
}); | ||
} | ||
//test bench::single_thread_test ... bench: 44 ns/iter (+/- 1) | ||
#[bench] | ||
fn single_thread_test(b: &mut Bencher) { | ||
b.iter(|| { | ||
let now = Time::now(); | ||
}); | ||
} | ||
|
||
#[bench] | ||
fn mult_thread_test(b: &mut Bencher) { | ||
std::thread::spawn(move || { | ||
for _ in 0..100000 { | ||
let now = Time::now(); | ||
} | ||
}); | ||
b.iter(|| { | ||
#[bench] | ||
fn mult_thread_test(b: &mut Bencher) { | ||
std::thread::spawn(move || { | ||
for _ in 0..100000 { | ||
let now = Time::now(); | ||
}); | ||
} | ||
} | ||
}); | ||
b.iter(|| { | ||
let now = Time::now(); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters