performance - Why is the Rust random number generator slower with multiple instances running? -


i doing random number generation lotto simulation , wondering why slower when running multiple instances?

i running program under ubuntu 15.04 (linux kernel 4.2). rustc 1.7.0-nightly (d5e229057 2016-01-04)

overall cpu utilization 45% during these tests each individual thread taking 100% of thread.

here script using start multiple instances @ same time.

#!/usr/bin/env bash  pkill lotto_sim  _ in `seq 1 14`;     ./lotto_sim 15000000 1>> /var/log/syslog & done 

output:

took pt38.701900316s seconds generate 15000000 random tickets took pt39.193917241s seconds generate 15000000 random tickets took pt39.412279484s seconds generate 15000000 random tickets took pt39.492940352s seconds generate 15000000 random tickets took pt39.715433024s seconds generate 15000000 random tickets took pt39.726609237s seconds generate 15000000 random tickets took pt39.884151996s seconds generate 15000000 random tickets took pt40.025874106s seconds generate 15000000 random tickets took pt40.088332517s seconds generate 15000000 random tickets took pt40.112601899s seconds generate 15000000 random tickets took pt40.205958636s seconds generate 15000000 random tickets took pt40.227956170s seconds generate 15000000 random tickets took pt40.393753486s seconds generate 15000000 random tickets took pt40.465173616s seconds generate 15000000 random tickets 

however, single run gives output:

$ ./lotto_sim 15000000 took pt9.860698141s seconds generate 15000000 random tickets 

my understanding each process has it's own memory , doesn't share anything. correct?

here relevant code:

extern crate rand; extern crate itertools; extern crate time;  use std::env;  use rand::{rng, rand}; use itertools::itertools; use time::precisetime;  struct ticket {     whites: vec<u8>,     power_ball: u8,     is_power_play: bool, }  const power_play_percentage: u8 = 15; const white_min: u8 = 1; const white_max: u8 = 69; const power_ball_min: u8 = 1; const power_ball_max: u8 = 26;  impl rand ticket {     fn rand<r: rng>(rng: &mut r) -> self {         let pp_guess = rng.gen_range(0, 100);         let pp_value = pp_guess < power_play_percentage;          let mut whites_vec: vec<_> = (0..).map(|_| rng.gen_range(white_min, white_max + 1))                                           .unique().take(5).collect();         whites_vec.sort();          let pb_value = rng.gen_range(power_ball_min, power_ball_max + 1);         ticket { whites: whites_vec, power_ball: pb_value, is_power_play: pp_value}     } }  fn gen_test(num_tickets: i64) {     let mut rng = rand::thread_rng();     let _: vec<_> = rng.gen_iter::<ticket>()             .take(num_tickets usize)             .collect(); }  fn main() {     let args: vec<_> = env::args().collect();     let num_tickets: i64 = args[1].parse::<i64>().unwrap();      let start = precisetime::now();     gen_test(num_tickets);     let end = precisetime::now();      println!("took {} seconds generate {} random tickets", start.to(end), num_tickets);  } 

edit:

maybe better question how debug , figure out? within program or within os find performance hindrances? new rust , lower level programming relies heavily on os.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -