daily pastebin goal
37%
SHARE
TWEET

Untitled

a guest Oct 12th, 2017 102 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. fn gen_data(cap: usize) -> Vec<f64> {
  2.     let mut ret = vec![0f64; cap];
  3.     let start = std::time::Instant::now();
  4.     for i in 0..cap {
  5.         ret[i] += 1f64;
  6.     }
  7.     let end = std::time::Instant::now();
  8.     println!("Took {:?} to generate", end - start);
  9.     return ret;
  10. }
  11. fn gen_data2(cap: usize) -> Vec<f64> {
  12.     let mut ret = Vec::with_capacity(cap);
  13.     let start = std::time::Instant::now();
  14.     for i in 0..cap {
  15.         ret.push(1f64);
  16.     }
  17.     let end = std::time::Instant::now();
  18.     println!("Took {:?} to generate", end - start);
  19.     return ret;
  20. }
  21. fn gen_data3(cap: usize) -> Vec<f64> {
  22.     let mut ret = vec![0f64; cap];
  23.     let start = std::time::Instant::now();
  24.     for v in ret.iter_mut() {
  25.         *v += 1f64;
  26.     }
  27.     let end = std::time::Instant::now();
  28.     println!("Took {:?} to generate", end - start);
  29.     return ret;
  30. }
  31.  
  32. fn main() {
  33.     for _ in 1..10 {
  34.         gen_data(100000);
  35.     }
  36.     println!("");
  37.     for _ in 1..10 {
  38.         gen_data2(100000);
  39.     }
  40.     println!("");
  41.     for _ in 1..10 {
  42.         gen_data3(100000);
  43.     }
  44.     let handle = std::io::stdin();
  45.     let mut in_buf = String::new();
  46.     handle.read_line(&mut in_buf).expect(":(");
  47. }
RAW Paste Data
Top