-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhash-bun.js
More file actions
73 lines (60 loc) · 1.58 KB
/
Copy pathhash-bun.js
File metadata and controls
73 lines (60 loc) · 1.58 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import { Bench } from './lib/bench.js'
const encoder = new TextEncoder()
const hello = encoder.encode('hello')
const len = hello.length
const iter = parseInt(args[0] || '5', 10)
const runs = parseInt(args[1] || '3000000', 10)
const bench = new Bench()
const expected = [
93, 65, 64, 42, 188, 75, 42, 118, 185, 113, 157, 145, 16, 23, 197, 146
]
Bun.MD5.hash(hello).forEach((v, i) => assert(v === expected[i]))
Bun.MD5.hash('hello').forEach((v, i) => assert(v === expected[i]))
{
const { hash } = Bun.MD5
for (let i = 0; i < iter; i++) {
bench.start('md5-string')
for (let j = 0; j < runs; j++) {
assert(hash('hello').length === 16)
}
bench.end(runs, len)
}
}
{
const { hash } = Bun.MD5
for (let i = 0; i < iter; i++) {
bench.start('md5-buffer')
for (let j = 0; j < runs; j++) {
assert(hash(hello).length === 16)
}
bench.end(runs, len)
}
}
/*
const expectedsha256 = [
44, 242, 77, 186, 95, 176, 163, 14, 38, 232, 59, 42, 197, 185, 226, 158, 27,
22, 30, 92, 31, 167, 66, 94, 115, 4, 51, 98, 147, 139, 152, 36
]
Bun.SHA256.hash(hello).forEach((v, i) => assert(v === expectedsha256[i]))
Bun.SHA256.hash('hello').forEach((v, i) => assert(v === expectedsha256[i]))
{
const { hash } = Bun.SHA256
for (let i = 0; i < iter; i++) {
bench.start('sha256-string')
for (let j = 0; j < runs; j++) {
hash('hello')
}
bench.end(runs)
}
}
{
const { hash } = Bun.SHA256
for (let i = 0; i < iter; i++) {
bench.start('sha256-buffer')
for (let j = 0; j < runs; j++) {
hash(hello)
}
bench.end(runs)
}
}
*/