egedit: do not save cursor movement in undo -- this is my stupid habit, and it comple...
[iv.d.git] / hash / test_streaming.d
blob008747bae044e9777b5b7cec3be52bb03e87ee8f
1 import iv.hash.fasthash;
2 import iv.hash.joaat;
3 import iv.hash.murhash;
5 import iv.pxclock;
6 import iv.vfs.io;
8 /*
9 TESTHASH(x86, 32, 1234, "Hello, world!", "faf6cdb3");
10 TESTHASH(x86, 32, 4321, "Hello, world!", "bf505788");
11 TESTHASH(x86, 32, 1234, "xxxxxxxxxxxxxxxxxxxxxxxxxxxx", "8905ac28");
12 TESTHASH(x86, 32, 1234, "", "0f2cc00b");
15 void doHash(T, bool norand=false) (scope const(void)[] buf, uint eta, uint seed=0) if (is(T == struct)) {
16 T hash;
17 if (seed) hash.reset(seed);
18 static if (norand) {
19 hash.put(buf);
20 } else {
21 while (buf.length > 0) {
22 import std.random : uniform;
23 auto len = uniform!"[]"(0, buf.length);
24 hash.put(buf[0..len]);
25 buf = buf[len..$];
28 auto h = hash.finish32();
29 if (h != eta) assert(0, T.stringof~" failed "~(norand ? "initial " : "")~"streaming test");
33 void doTest(T) (scope const(void)[] buf, uint eta, uint seed=0) if (is(T == struct)) {
34 enum Tries = 100000;
35 write(T.stringof, ": ");
36 auto stt = clockMilli();
37 doHash!(T, true)(buf, eta, seed);
38 foreach (immutable _; 0..Tries) doHash!T(buf, eta, seed);
39 auto ett = clockMilli()-stt;
40 writeln(Tries, " times took ", ett, " milliseconds");
44 void main () {
45 //doTest!JoaatHash();
46 //doTest!FastHash();
47 doTest!MurHash("Hello, world!", 0xfaf6cdb3U, 1234);
48 doTest!MurHash("Hello, world!", 0xbf505788U, 4321);
49 doTest!MurHash("xxxxxxxxxxxxxxxxxxxxxxxxxxxx", 0x8905ac28U, 1234);
50 doTest!MurHash("", 0x0f2cc00bU, 1234);