forked from ai/nanoid
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbenchmark
More file actions
executable file
·34 lines (30 loc) · 825 Bytes
/
Copy pathbenchmark
File metadata and controls
executable file
·34 lines (30 loc) · 825 Bytes
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
#!/usr/bin/env node
var benchmark = require('benchmark')
var shortid = require('shortid')
var uuid4 = require('uuid/v4')
var chalk = require('chalk')
var generate = require('./generate')
var nanoid = require('./')
var suite = new benchmark.Suite()
function formatNumber (number) {
return String(number).replace(/\d\d\d$/, ',$&')
}
suite
.add('nanoid', function () {
nanoid()
})
.add('nanoid/generate', function () {
generate('1234567890abcdef-', 10)
})
.add('uuid/v4', function () {
uuid4()
})
.add('shortid', function () {
shortid()
})
.on('cycle', function (event) {
var name = event.target.name.padEnd('nanoid/generate'.length)
var hz = formatNumber(event.target.hz.toFixed(0)).padStart(7)
process.stdout.write(name + ' ' + chalk.bold(hz) + ' ops/sec \n')
})
.run()