-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathbench.js
54 lines (46 loc) · 990 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
'use strict'
const Benchmark = require('benchmark')
const jwt = require('./')
const payload = {
iss: 'my_issurer',
aud: 'World',
iat: new Date().getTime(),
typ: '/online/transactionstatus/v2',
request: {
myTransactionId: uuid(),
merchantTransactionId: uuid(),
status: 'SUCCESS'
}
}
const secret = 'TOPSECRETTTTT'
var holdToken
console.log('starting `json-web-token` benchmark')
new Benchmark.Suite()
.add('json-web-token#encode', () => {
jwt.encode(secret, payload, (err, token) => {
if (err) {
throw err
}
holdToken = token
})
})
.add('json-web-token#decode', () => {
jwt.decode(secret, holdToken, (err, decoded) => {
if (err) {
throw err
}
})
})
.on('cycle', (event) => {
console.log(String(event.target))
})
.on('complete', () => {
console.log('benchmark finish')
})
.run({ async: true })
//
//
//
function uuid () {
return (~~(Math.random() * 1e9)).toString(36)
}