Skip to content

Commit 6752b00

Browse files
committed
add noop demo
1 parent 6231444 commit 6752b00

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

rayon-demo/src/main.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ mod life;
99
mod matmul;
1010
mod mergesort;
1111
mod nbody;
12+
mod noop;
1213
mod quicksort;
1314
mod sieve;
1415
mod tsp;
@@ -81,6 +82,7 @@ Benchmarks:
8182
- sieve: Finding primes using a Sieve of Eratosthenes.
8283
- matmul: Parallel matrix multiplication.
8384
- mergesort: Parallel mergesort.
85+
- noop: Launch empty tasks to measure CPU usage.
8486
- quicksort: Parallel quicksort.
8587
- tsp: Traveling salesman problem solver (sample data sets in `data/tsp`).
8688
";
@@ -106,6 +108,7 @@ fn main() {
106108
"sieve" => sieve::main(&args[1..]),
107109
"tsp" => tsp::main(&args[1..]),
108110
"life" => life::main(&args[1..]),
111+
"noop" => noop::main(&args[1..]),
109112
_ => usage(),
110113
}
111114
}

rayon-demo/src/noop/mod.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const USAGE: &str = "
2+
Usage: noop [--sleep N] [--iters N]
3+
4+
Noop loop to measure CPU usage. See rayon-rs/rayon#642.
5+
6+
Options:
7+
--sleep N How long to sleep (in millis) between doing a spawn. [default: 10]
8+
--iters N Total time to execution (in millis). [default: 100]
9+
";
10+
11+
use docopt::Docopt;
12+
13+
#[derive(Deserialize)]
14+
pub struct Args {
15+
flag_sleep: u64,
16+
flag_iters: u64,
17+
}
18+
19+
pub fn main(args: &[String]) {
20+
let args: Args = Docopt::new(USAGE)
21+
.and_then(|d| d.argv(args).deserialize())
22+
.unwrap_or_else(|e| e.exit());
23+
24+
for _ in 1..args.flag_iters {
25+
std::thread::sleep(std::time::Duration::from_millis(args.flag_sleep));
26+
rayon::spawn(move || { } );
27+
}
28+
}

0 commit comments

Comments
 (0)