@@ -4,19 +4,36 @@ const benchmark = require('benchmark')
4
4
const suite = new benchmark . Suite ( )
5
5
6
6
const schema = {
7
- ' title' : 'Example Schema' ,
8
- ' type' : 'object' ,
9
- ' properties' : {
10
- ' firstName' : {
11
- ' type' : 'string'
7
+ title : 'Example Schema' ,
8
+ type : 'object' ,
9
+ properties : {
10
+ firstName : {
11
+ type : 'string'
12
12
} ,
13
- ' lastName' : {
14
- ' type' : [ 'string' , 'null' ]
13
+ lastName : {
14
+ type : [ 'string' , 'null' ]
15
15
} ,
16
- 'age' : {
17
- 'description' : 'Age in years' ,
18
- 'type' : 'integer' ,
19
- 'minimum' : 0
16
+ age : {
17
+ description : 'Age in years' ,
18
+ type : 'integer' ,
19
+ minimum : 0
20
+ }
21
+ }
22
+ }
23
+ const schemaCJS = {
24
+ title : 'Example Schema' ,
25
+ type : 'object' ,
26
+ properties : {
27
+ firstName : {
28
+ type : 'string'
29
+ } ,
30
+ lastName : {
31
+ type : [ 'string' , 'null' ]
32
+ } ,
33
+ age : {
34
+ description : 'Age in years' ,
35
+ type : 'number' ,
36
+ minimum : 0
20
37
}
21
38
}
22
39
}
@@ -27,6 +44,12 @@ const arraySchema = {
27
44
items : schema
28
45
}
29
46
47
+ const arraySchemaCJS = {
48
+ title : 'array schema' ,
49
+ type : 'array' ,
50
+ items : schemaCJS
51
+ }
52
+
30
53
const obj = {
31
54
firstName : 'Matteo' ,
32
55
lastName : 'Collina' ,
@@ -35,6 +58,16 @@ const obj = {
35
58
36
59
const multiArray = [ ]
37
60
61
+ const JSTR = require ( 'json-strify' )
62
+ const JSTRStringify = JSTR ( schemaCJS )
63
+ const JSTRArray = JSTR ( arraySchemaCJS )
64
+ const JSTRInstance = JSTR ( )
65
+
66
+ const CJS = require ( 'compile-json-stringify' )
67
+ const CJSStringify = CJS ( schemaCJS )
68
+ const CJSStringifyArray = CJS ( arraySchemaCJS )
69
+ const CJSStringifyString = CJS ( { type : 'string' } )
70
+
38
71
const FJS = require ( '.' )
39
72
const stringify = FJS ( schema )
40
73
const stringifyUgly = FJS ( schema , { uglify : true } )
@@ -60,6 +93,12 @@ for (i = 0; i < 1000; i++) {
60
93
suite . add ( 'FJS creation' , function ( ) {
61
94
FJS ( schema )
62
95
} )
96
+ suite . add ( 'JSTR creation' , function ( ) {
97
+ JSTR ( schemaCJS )
98
+ } )
99
+ suite . add ( 'CJS creation' , function ( ) {
100
+ CJS ( schemaCJS )
101
+ } )
63
102
64
103
suite . add ( 'JSON.stringify array' , function ( ) {
65
104
JSON . stringify ( multiArray )
@@ -73,6 +112,14 @@ suite.add('fast-json-stringify-uglified array', function () {
73
112
stringifyArrayUgly ( multiArray )
74
113
} )
75
114
115
+ suite . add ( 'json-strify array' , function ( ) {
116
+ JSTRArray ( multiArray )
117
+ } )
118
+
119
+ suite . add ( 'compile-json-stringify array' , function ( ) {
120
+ CJSStringifyArray ( multiArray )
121
+ } )
122
+
76
123
suite . add ( 'JSON.stringify long string' , function ( ) {
77
124
JSON . stringify ( str )
78
125
} )
@@ -85,6 +132,14 @@ suite.add('fast-json-stringify-uglified long string', function () {
85
132
stringifyStringUgly ( str )
86
133
} )
87
134
135
+ suite . add ( 'json-strify long string' , function ( ) {
136
+ JSTRInstance ( str )
137
+ } )
138
+
139
+ suite . add ( 'compile-json-stringify long string' , function ( ) {
140
+ CJSStringifyString ( str )
141
+ } )
142
+
88
143
suite . add ( 'JSON.stringify short string' , function ( ) {
89
144
JSON . stringify ( 'hello world' )
90
145
} )
@@ -97,6 +152,14 @@ suite.add('fast-json-stringify-uglified short string', function () {
97
152
stringifyStringUgly ( 'hello world' )
98
153
} )
99
154
155
+ suite . add ( 'json-strify short string' , function ( ) {
156
+ JSTRInstance ( 'hello world' )
157
+ } )
158
+
159
+ suite . add ( 'compile-json-stringify short string' , function ( ) {
160
+ CJSStringifyString ( 'hello world' )
161
+ } )
162
+
100
163
suite . add ( 'JSON.stringify obj' , function ( ) {
101
164
JSON . stringify ( obj )
102
165
} )
@@ -109,6 +172,14 @@ suite.add('fast-json-stringify-uglified obj', function () {
109
172
stringifyUgly ( obj )
110
173
} )
111
174
175
+ suite . add ( 'json-strify obj' , function ( ) {
176
+ JSTRStringify ( obj )
177
+ } )
178
+
179
+ suite . add ( 'compile-json-stringify obj' , function ( ) {
180
+ CJSStringify ( obj )
181
+ } )
182
+
112
183
suite . on ( 'cycle' , cycle )
113
184
114
185
suite . run ( )
0 commit comments