forked from mcollina/hyperid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
benchmark.js
54 lines (39 loc) · 913 Bytes
/
benchmark.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
50
51
52
53
54
'use strict'
const benchmark = require('benchmark')
const Hashids = require('hashids')
const shortid = require('shortid')
const nid = require('nid')
const uuid = require('uuid')
const hyperid = require('.')()
const suite = new benchmark.Suite()
const hashids = new Hashids('mybench')
suite.add('hashids process.hrtime', function () {
hashids.encode(process.hrtime())
})
let hashIdCounter = 0
suite.add('hashids counter', function () {
hashids.encode(hashIdCounter++)
})
suite.add('shortid', function () {
shortid()
})
suite.add('nid', function () {
nid()
})
suite.add('uuid.v4', function () {
uuid.v4()
})
suite.add('uuid.v1', function () {
uuid.v1()
})
suite.add('hyperid - variable length', function () {
hyperid()
})
suite.add('hyperid - fixed length', function () {
hyperid(true)
})
suite.on('cycle', cycle)
suite.run()
function cycle (e) {
console.log(e.target.toString())
}