-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
69 lines (63 loc) · 1.79 KB
/
index.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
'use strict';
const Benchmark = require('benchmark');
const encode = new Benchmark.Suite;
const decode = new Benchmark.Suite;
const jwtsimple = require('jwt-simple');
const jsonwebtoken = require('jsonwebtoken');
const njwt = require('njwt');
const jwtnode = require('jwt-node');
const jws = require('jws');
let token = {};
let secret = 'my53cr3tv4r';
let payload = {
foo: 'bar',
baz: 'qux',
quux: 'corge',
grault: {
garply: 'waldo',
fred: [
'plugh',
'xyzzy',
'thud'
]
}
};
encode
.add('jwt-simple', () => {
token.jwtsimple = jwtsimple.encode(payload, secret);
})
.add('jsonwebtoken', () => {
token.jsonwebtoken = jsonwebtoken.sign(payload, secret);
})
.add('njwt', () => {
token.njwt = njwt.create(payload, secret).compact();
})
.add('jwt-node', () => {
token.jwtnode = jwtnode.create(payload, secret).compact();
})
.add('jws', () => {
token.jws = jws.sign({header: {alg: 'HS256'}, payload: payload, secret: secret});
})
.on('cycle', (event) => console.log(String(event.target)))
.on('complete', function () { console.log('Fastest encoder is ' + this.filter('fastest').map('name') + "\n") })
.run({ 'async': false });
decode
.add('jwt-simple', () => {
jwtsimple.decode(token.jwtsimple, secret);
})
.add('jsonwebtoken', () => {
jsonwebtoken.verify(token.jsonwebtoken, secret);
})
.add('njwt', () => {
njwt.verify(token.njwt, secret);
})
.add('jwt-node', () => {
jwtnode.verify(token.jwtnode, secret);
})
.add('jws', () => {
if (jws.verify(token.jws, 'HS256', secret))
jws.decode(token.jws);
})
.on('cycle', (event) => console.log(String(event.target)))
.on('complete', function () { console.log('Fastest decoder is ' + this.filter('fastest').map('name') + "\n"); })
.run({ 'async': false });