Skip to content

Instantly share code, notes, and snippets.

@nelhage
Created November 23, 2016 04:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nelhage/c99ad393a45c921ed5b1fffe48228143 to your computer and use it in GitHub Desktop.
Save nelhage/c99ad393a45c921ed5b1fffe48228143 to your computer and use it in GitHub Desktop.
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