forked from webpack/webpack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxxhash64.js
49 lines (47 loc) · 1.18 KB
/
xxhash64.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
const createHash = require("../lib/util/createHash");
const compare = require("./micro-compare");
for (const size of [
1, 10, 20, 40, 60, 80, 100, 200, 400, 1000, 1001, 5000, 8183, 8184, 8185,
10000, 20000, 32768, 32769, 50000, 100000, 200000
]) {
const longString = require("crypto").randomBytes(size).toString("hex");
const buffer = require("crypto").randomBytes(size * 2);
console.log(
`string ${longString.length} chars: ` +
compare(
"wasm xxhash64",
() => {
const hash = createHash("xxhash64");
hash.update(longString);
hash.update(longString);
return hash.digest("hex");
},
"native md4",
() => {
const hash = createHash("native-md4");
hash.update(longString);
hash.update(longString);
return hash.digest("hex");
}
)
);
console.log(
`buffer ${buffer.length} bytes: ` +
compare(
"wasm xxhash64",
() => {
const hash = createHash("xxhash64");
hash.update(buffer);
hash.update(buffer);
return hash.digest("hex");
},
"native md4",
() => {
const hash = createHash("native-md4");
hash.update(buffer);
hash.update(buffer);
return hash.digest("hex");
}
)
);
}