Skip to content

Commit

Permalink
add noop demo
Browse files Browse the repository at this point in the history
  • Loading branch information
nikomatsakis committed Sep 14, 2019
1 parent 6231444 commit 6752b00
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
3 changes: 3 additions & 0 deletions rayon-demo/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ mod life;
mod matmul;
mod mergesort;
mod nbody;
mod noop;
mod quicksort;
mod sieve;
mod tsp;
Expand Down Expand Up @@ -81,6 +82,7 @@ Benchmarks:
- sieve: Finding primes using a Sieve of Eratosthenes.
- matmul: Parallel matrix multiplication.
- mergesort: Parallel mergesort.
- noop: Launch empty tasks to measure CPU usage.
- quicksort: Parallel quicksort.
- tsp: Traveling salesman problem solver (sample data sets in `data/tsp`).
";
Expand All @@ -106,6 +108,7 @@ fn main() {
"sieve" => sieve::main(&args[1..]),
"tsp" => tsp::main(&args[1..]),
"life" => life::main(&args[1..]),
"noop" => noop::main(&args[1..]),
_ => usage(),
}
}
Expand Down
28 changes: 28 additions & 0 deletions rayon-demo/src/noop/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const USAGE: &str = "
Usage: noop [--sleep N] [--iters N]
Noop loop to measure CPU usage. See rayon-rs/rayon#642.
Options:
--sleep N How long to sleep (in millis) between doing a spawn. [default: 10]
--iters N Total time to execution (in millis). [default: 100]
";

use docopt::Docopt;

#[derive(Deserialize)]
pub struct Args {
flag_sleep: u64,
flag_iters: u64,
}

pub fn main(args: &[String]) {
let args: Args = Docopt::new(USAGE)
.and_then(|d| d.argv(args).deserialize())
.unwrap_or_else(|e| e.exit());

for _ in 1..args.flag_iters {
std::thread::sleep(std::time::Duration::from_millis(args.flag_sleep));
rayon::spawn(move || { } );
}
}

0 comments on commit 6752b00

Please sign in to comment.