Last active
August 29, 2015 14:03
-
-
Save thedeemon/9fb6e9b29e5cd5bfd8b0 to your computer and use it in GitHub Desktop.
This file contains 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
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