Skip to content

Instantly share code, notes, and snippets.

@jamwt
Created March 27, 2018 20:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamwt/ebabdc7ae647e5c79054f1acd3135639 to your computer and use it in GitHub Desktop.
Save jamwt/ebabdc7ae647e5c79054f1acd3135639 to your computer and use it in GitHub Desktop.
#![feature(test)]
extern crate rayon;
extern crate test;
#[cfg(test)]
mod tests {
use test::Bencher;
use rayon::prelude::*;
#[bench]
fn single(b: &mut Bencher) {
let array: Vec<usize> = (0..1_000_000).collect();
b.iter(|| {
let v: usize = array.iter().sum();
assert_eq!(v, 499999500000);
});
}
#[bench]
fn parallel(b: &mut Bencher) {
let array: Vec<usize> = (0..1_000_000).collect();
b.iter(|| {
let v: usize = array.par_iter().sum();
assert_eq!(v, 499999500000);
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment