@@ -5,46 +5,96 @@ const uuidv1 = (typeof window !== 'undefined' && window.uuidv1) || require('uuid
5
5
const uuidv4 = ( typeof window !== 'undefined' && window . uuidv4 ) || require ( 'uuid' ) . v4 ;
6
6
const uuidv3 = ( typeof window !== 'undefined' && window . uuidv3 ) || require ( 'uuid' ) . v3 ;
7
7
const uuidv5 = ( typeof window !== 'undefined' && window . uuidv5 ) || require ( 'uuid' ) . v5 ;
8
+ const uuidParse = ( typeof window !== 'undefined' && window . uuidParse ) || require ( 'uuid' ) . parse ;
9
+ const uuidStringify =
10
+ ( typeof window !== 'undefined' && window . uuidStringify ) || require ( 'uuid' ) . stringify ;
8
11
9
12
console . log ( 'Starting. Tests take ~1 minute to run ...' ) ;
10
13
11
- const array = new Array ( 16 ) ;
12
-
13
- const suite = new Benchmark . Suite ( {
14
- onError ( event ) {
15
- console . error ( event . target . error ) ;
16
- } ,
17
- } ) ;
18
-
19
- suite
20
- . add ( 'uuidv1()' , function ( ) {
21
- uuidv1 ( ) ;
22
- } )
23
- . add ( 'uuidv1() fill existing array' , function ( ) {
24
- try {
25
- uuidv1 ( null , array , 0 ) ;
26
- } catch ( err ) {
27
- // The spec (https://tools.ietf.org/html/rfc4122#section-4.2.1.2) defines that only 10M/s v1
28
- // UUIDs can be generated on a single node. This library throws an error if we hit that limit
29
- // (which can happen on modern hardware and modern Node.js versions).
30
- }
31
- } )
32
- . add ( 'uuidv4()' , function ( ) {
33
- uuidv4 ( ) ;
34
- } )
35
- . add ( 'uuidv4() fill existing array' , function ( ) {
36
- uuidv4 ( null , array , 0 ) ;
37
- } )
38
- . add ( 'uuidv3()' , function ( ) {
39
- uuidv3 ( 'hello.example.com' , uuidv3 . DNS ) ;
40
- } )
41
- . add ( 'uuidv5()' , function ( ) {
42
- uuidv5 ( 'hello.example.com' , uuidv5 . DNS ) ;
43
- } )
44
- . on ( 'cycle' , function ( event ) {
45
- console . log ( event . target . toString ( ) ) ;
46
- } )
47
- . on ( 'complete' , function ( ) {
48
- console . log ( 'Fastest is ' + this . filter ( 'fastest' ) . map ( 'name' ) ) ;
49
- } )
50
- . run ( ) ;
14
+ function testParseAndStringify ( ) {
15
+ const suite = new Benchmark . Suite ( {
16
+ onError ( event ) {
17
+ console . error ( event . target . error ) ;
18
+ } ,
19
+ } ) ;
20
+
21
+ const BYTES = [
22
+ 0x0f ,
23
+ 0x5a ,
24
+ 0xbc ,
25
+ 0xd1 ,
26
+ 0xc1 ,
27
+ 0x94 ,
28
+ 0x47 ,
29
+ 0xf3 ,
30
+ 0x90 ,
31
+ 0x5b ,
32
+ 0x2d ,
33
+ 0xf7 ,
34
+ 0x26 ,
35
+ 0x3a ,
36
+ 0x08 ,
37
+ 0x4b ,
38
+ ] ;
39
+
40
+ suite
41
+ . add ( 'uuidStringify()' , function ( ) {
42
+ uuidStringify ( BYTES ) ;
43
+ } )
44
+ . add ( 'uuidParse()' , function ( ) {
45
+ uuidParse ( '0f5abcd1-c194-47f3-905b-2df7263a084b' ) ;
46
+ } )
47
+ . on ( 'cycle' , function ( event ) {
48
+ console . log ( event . target . toString ( ) ) ;
49
+ } )
50
+ . on ( 'complete' , function ( ) {
51
+ console . log ( '---\n' ) ;
52
+ } )
53
+ . run ( ) ;
54
+ }
55
+
56
+ function testGeneration ( ) {
57
+ const array = new Array ( 16 ) ;
58
+
59
+ const suite = new Benchmark . Suite ( {
60
+ onError ( event ) {
61
+ console . error ( event . target . error ) ;
62
+ } ,
63
+ } ) ;
64
+
65
+ suite
66
+ . add ( 'uuidv1()' , function ( ) {
67
+ uuidv1 ( ) ;
68
+ } )
69
+ . add ( 'uuidv1() fill existing array' , function ( ) {
70
+ try {
71
+ uuidv1 ( null , array , 0 ) ;
72
+ } catch ( err ) {
73
+ // The spec (https://tools.ietf.org/html/rfc4122#section-4.2.1.2) defines that only 10M/s v1
74
+ // UUIDs can be generated on a single node. This library throws an error if we hit that limit
75
+ // (which can happen on modern hardware and modern Node.js versions).
76
+ }
77
+ } )
78
+ . add ( 'uuidv4()' , function ( ) {
79
+ uuidv4 ( ) ;
80
+ } )
81
+ . add ( 'uuidv4() fill existing array' , function ( ) {
82
+ uuidv4 ( null , array , 0 ) ;
83
+ } )
84
+ . add ( 'uuidv3()' , function ( ) {
85
+ uuidv3 ( 'hello.example.com' , uuidv3 . DNS ) ;
86
+ } )
87
+ . add ( 'uuidv5()' , function ( ) {
88
+ uuidv5 ( 'hello.example.com' , uuidv5 . DNS ) ;
89
+ } )
90
+ . on ( 'cycle' , function ( event ) {
91
+ console . log ( event . target . toString ( ) ) ;
92
+ } )
93
+ . on ( 'complete' , function ( ) {
94
+ console . log ( 'Fastest is ' + this . filter ( 'fastest' ) . map ( 'name' ) ) ;
95
+ } )
96
+ . run ( ) ;
97
+ }
98
+
99
+ testParseAndStringify ( ) ;
100
+ testGeneration ( ) ;
0 commit comments