-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbench.js
37 lines (31 loc) · 802 Bytes
/
bench.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
//@flow
const { Suite } = require('benchmark')
const {
bigInt2str,
str2bigInt,
} = require('./lib')
function fourDigitRandom() {
return (Math.random() * 9e3 + 1e3) | 0
}
function eightDigitHex() {
return fourDigitRandom().toString(16) + fourDigitRandom().toString(16)
}
const fullBench = new Suite('full bench')
.add('bigInt2str', () => bigInt2str([
fourDigitRandom(),
fourDigitRandom(),
fourDigitRandom(),
0, 0, 0
], 16))
.add('str2bigInt', () => str2bigInt(eightDigitHex(), 16))
.on('cycle', (event) => {
console.log(String(event.target))
})
// .on('complete', function() {
// console.log('Fastest is ' + this.filter('fastest').map('name'))
// // console.log(this[0].stats)
// })
fullBench.run()
fullBench.run()
fullBench.run()
fullBench.run()