-
-
Notifications
You must be signed in to change notification settings - Fork 879
/
benchmark.js
58 lines (56 loc) · 1.92 KB
/
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
55
56
57
58
const Benchmark = require('benchmark');
const { v1: uuidv1, v4: uuidv4, v3: uuidv3, v5: uuidv5 } = require('uuid');
const MY_NAMESPACE = '55238d15-c926-4598-b49d-cf4e913ba13c';
const suite = new Benchmark.Suite();
suite
.add('uuidv1()', function () {
uuidv1();
})
.add('uuidv1() fill existing array', function () {
const array = new Array();
uuidv1(null, array, 0);
})
.add('uuidv4()', function () {
uuidv4();
})
.add('uuidv4() fill existing array', function () {
const array = new Array();
uuidv4(null, array, 0);
})
.add('uuidv3() DNS', function () {
uuidv3('hello.example.com', uuidv3.DNS);
})
.add('uuidv3() URL', function () {
// ... using predefined URL namespace (for, well, URLs)
uuidv3('http://example.com/hello', uuidv3.URL);
})
.add('uuidv3() MY_NAMESPACE', function () {
// ... using a custom namespace
//
// Note: Custom namespaces should be a UUID string specific to your application!
// E.g. the one here was generated using this modules `uuid` CLI.
uuidv3('Hello, World!', MY_NAMESPACE);
})
.add('uuidv5() DNS', function () {
// ... using predefined DNS namespace (for domain names)
uuidv5('hello.example.com', uuidv5.DNS);
})
.add('uuidv5() URL', function () {
// ... using predefined URL namespace (for, well, URLs)
uuidv5('http://example.com/hello', uuidv5.URL);
})
.add('uuidv5() MY_NAMESPACE', function () {
// ... using a custom namespace
//
// Note: Custom namespaces should be a UUID string specific to your application!
// E.g. the one here was generated using this modules `uuid` CLI.
// const MY_NAMESPACE = '1b671a64-40d5-491e-99b0-da01ff1f3341';
uuidv5('Hello, World!', MY_NAMESPACE);
})
.on('cycle', function (event) {
console.log(String(event.target));
})
.on('complete', function () {
console.log('Fastest is ' + this.filter('fastest').map('name'));
})
.run({ async: true });