-
Notifications
You must be signed in to change notification settings - Fork 118
Expand file tree
/
Copy pathhash.ts
More file actions
118 lines (105 loc) · 2.63 KB
/
hash.ts
File metadata and controls
118 lines (105 loc) · 2.63 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import rnqc from 'react-native-quick-crypto';
import { sha256 } from '@noble/hashes/sha2';
// @ts-expect-error - crypto-browserify is not typed
import browserify from 'crypto-browserify';
import type { BenchFn } from '../../types/benchmarks';
import { Bench } from 'tinybench';
import { text1MB, text8MB, buffer1MB, buffer8MB } from '../testData';
const hash_sha256_8mb_string: BenchFn = () => {
const bench = new Bench({
name: 'hash sha256 8MB string',
iterations: 3,
warmupIterations: 1,
time: 0,
});
bench
.add('rnqc', () => {
const hash = rnqc.createHash('sha256');
hash.update(text8MB);
hash.digest('hex');
})
.add('@noble/hashes/sha256', () => {
sha256(text8MB);
})
.add('browserify', () => {
const hash = browserify.createHash('sha256');
hash.update(text8MB);
hash.digest('hex');
});
return bench;
};
const hash_sha256_1mb_string: BenchFn = () => {
const bench = new Bench({
name: 'hash sha256 1MB string',
iterations: 5,
warmupIterations: 2,
time: 0,
});
bench
.add('rnqc', () => {
const hash = rnqc.createHash('sha256');
hash.update(text1MB);
hash.digest('hex');
})
.add('@noble/hashes/sha256', () => {
sha256(text1MB);
})
.add('browserify', () => {
const hash = browserify.createHash('sha256');
hash.update(text1MB);
hash.digest('hex');
});
return bench;
};
const hash_sha256_8mb_buffer: BenchFn = () => {
const bench = new Bench({
name: 'hash sha256 8MB Buffer',
iterations: 3,
warmupIterations: 1,
time: 0,
});
bench
.add('rnqc', () => {
const hash = rnqc.createHash('sha256');
hash.update(buffer8MB);
hash.digest('hex');
})
.add('@noble/hashes/sha256', () => {
sha256(buffer8MB);
})
.add('browserify', () => {
const hash = browserify.createHash('sha256');
hash.update(buffer8MB);
hash.digest('hex');
});
return bench;
};
const hash_sha256_1mb_buffer: BenchFn = () => {
const bench = new Bench({
name: 'hash sha256 1MB Buffer',
iterations: 5,
warmupIterations: 2,
time: 0,
});
bench
.add('rnqc', () => {
const hash = rnqc.createHash('sha256');
hash.update(buffer1MB);
hash.digest('hex');
})
.add('@noble/hashes/sha256', () => {
sha256(buffer1MB);
})
.add('browserify', () => {
const hash = browserify.createHash('sha256');
hash.update(buffer1MB);
hash.digest('hex');
});
return bench;
};
export default [
hash_sha256_1mb_string,
hash_sha256_1mb_buffer,
hash_sha256_8mb_string,
hash_sha256_8mb_buffer,
];