Created
November 23, 2016 04:09
-
-
Save nelhage/c99ad393a45c921ed5b1fffe48228143 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
use std::collections::hash_set::HashSet; | |
use std::vec::Vec; | |
use std::time::{Instant,Duration}; | |
use std::env; | |
const SAMPLE_INTERVAL : usize = 1000; | |
fn duration_ns(d : Duration) -> i64 { | |
return (d.as_secs() as i64) * 1000000000 + (d.subsec_nanos() as i64); | |
} | |
struct DataPoint { | |
i : u64, | |
ns : i64, | |
} | |
fn main() { | |
let limit = env::args().nth(1).unwrap().parse::<u32>().unwrap(); | |
let mut one = HashSet::new(); | |
for i in 1..limit { | |
one.insert(i); | |
} | |
let mid = Instant::now(); | |
let mut two = HashSet::with_capacity(one.capacity() / 2); | |
let mut ts = Vec::with_capacity(one.len() / SAMPLE_INTERVAL); | |
let mut i = 0; | |
for v in one { | |
i += 1; | |
if i % SAMPLE_INTERVAL == 0 { | |
ts.push(DataPoint{ | |
i: i as u64, | |
ns: duration_ns(Instant::now().duration_since(mid)) | |
}); | |
} | |
two.insert(v); | |
} | |
println!("n,ns"); | |
for d in ts { | |
println!("{},{}", d.i, d.ns); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment