Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extern crate rand;
- extern crate rayon;
- use rand::Rng;
- use rand::distributions::Alphanumeric;
- use rayon::prelude::*;
- use std::time::Instant;
- fn main() {
- for _ in 0..10 {
- let timer = Instant::now();
- let vec: Vec<String> = (0..100_000)
- .into_par_iter()
- .map_init(
- || rand::thread_rng(),
- |rng, _| rng.sample_iter(&Alphanumeric).take(100).collect()
- ).collect();
- let overall_count: u32 =
- (0..1000)
- .into_par_iter()
- .fold(|| 0u32, |acc, _| {
- let needle: String = rand::thread_rng()
- .sample_iter(&Alphanumeric)
- .take(20)
- .collect();
- if (&vec).iter().any(|s100| {
- s100.contains(&needle)
- }) {
- acc + 1
- } else {
- acc
- }
- })
- .sum();
- println!("Found {} instances of in {:.2} secs", overall_count,
- timer.elapsed().as_secs_f64());
- }
- }
Add Comment
Please, Sign In to add comment