Created
March 27, 2018 20:01
-
-
Save jamwt/ebabdc7ae647e5c79054f1acd3135639 to your computer and use it in GitHub Desktop.
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
#![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