Skip to content

Instantly share code, notes, and snippets.

@thedeemon
Last active August 29, 2015 14:03
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 thedeemon/9fb6e9b29e5cd5bfd8b0 to your computer and use it in GitHub Desktop.
Save thedeemon/9fb6e9b29e5cd5bfd8b0 to your computer and use it in GitHub Desktop.
void readAndMeasure(K)(size_t num, string fname) {
auto data = cast(K[]) std.file.read(fname);
enforce(data.length == num);
auto h = new RHHash!(K,int);
measure("# " ~ typeof(h).stringof ~ ".make_histo", (){
foreach(x; data)
h[x]++;
});
measure("# " ~ typeof(h).stringof ~ ".read_histo", (){
int v = 0;
foreach(x; data)
v ^= h[x];
writeln(v);
});
foreach(x; data[0..4]) writeln(x, " ", h[x]);
}
void measure(string caption, scope void delegate() f) {
StopWatch sw;
sw.start();
f();
sw.stop();
writeln(caption, ": ", sw.peek.msecs, " ms");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment