1
- 'use strict '
1
+ 'use strictcreateAccelerator '
2
2
3
3
const benchmark = require ( 'benchmark' )
4
4
const suite = new benchmark . Suite ( )
@@ -118,6 +118,12 @@ const ajvSerialize = ajv.compileSerializer(schemaAJVJTD)
118
118
const ajvSerializeArray = ajv . compileSerializer ( arraySchemaAJVJTD )
119
119
const ajvSerializeString = ajv . compileSerializer ( { type : 'string' } )
120
120
121
+ const { createAccelerator } = require ( 'json-accelerator' )
122
+ const accelStringify = createAccelerator ( schema )
123
+ const accelArray = createAccelerator ( arraySchema )
124
+ const accelDate = FJS ( dateFormatSchema )
125
+ const accelString = FJS ( { type : 'string' } )
126
+
121
127
const getRandomString = ( length ) => {
122
128
if ( ! Number . isInteger ( length ) ) {
123
129
throw new Error ( 'Expected integer length' )
@@ -170,6 +176,9 @@ suite.add('CJS creation', function () {
170
176
suite . add ( 'AJV Serialize creation' , function ( ) {
171
177
ajv . compileSerializer ( schemaAJVJTD )
172
178
} )
179
+ suite . add ( 'json-accelerator creation' , function ( ) {
180
+ createAccelerator ( schema )
181
+ } )
173
182
174
183
suite . add ( 'JSON.stringify array' , function ( ) {
175
184
JSON . stringify ( multiArray )
@@ -179,6 +188,10 @@ suite.add('fast-json-stringify array default', function () {
179
188
stringifyArrayDefault ( multiArray )
180
189
} )
181
190
191
+ suite . add ( 'json-accelerator array' , function ( ) {
192
+ accelArray ( multiArray )
193
+ } )
194
+
182
195
suite . add ( 'fast-json-stringify array json-stringify' , function ( ) {
183
196
stringifyArrayJSONStringify ( multiArray )
184
197
} )
@@ -219,6 +232,10 @@ suite.add('fast-json-stringify long string', function () {
219
232
stringifyString ( str )
220
233
} )
221
234
235
+ suite . add ( 'json-accelerator long string' , function ( ) {
236
+ stringifyString ( str )
237
+ } )
238
+
222
239
suite . add ( 'compile-json-stringify long string' , function ( ) {
223
240
CJSStringifyString ( str )
224
241
} )
@@ -235,6 +252,10 @@ suite.add('fast-json-stringify short string', function () {
235
252
stringifyString ( 'hello world' )
236
253
} )
237
254
255
+ suite . add ( 'json-accelerator short string' , function ( ) {
256
+ accelString ( 'hello world' )
257
+ } )
258
+
238
259
suite . add ( 'compile-json-stringify short string' , function ( ) {
239
260
CJSStringifyString ( 'hello world' )
240
261
} )
@@ -251,6 +272,10 @@ suite.add('fast-json-stringify obj', function () {
251
272
stringify ( obj )
252
273
} )
253
274
275
+ suite . add ( 'json-accelerator obj' , function ( ) {
276
+ accelStringify ( obj )
277
+ } )
278
+
254
279
suite . add ( 'compile-json-stringify obj' , function ( ) {
255
280
CJSStringify ( obj )
256
281
} )
@@ -267,6 +292,10 @@ suite.add('fast-json-stringify date format', function () {
267
292
stringifyDate ( date )
268
293
} )
269
294
295
+ suite . add ( 'json-accelerate date format' , function ( ) {
296
+ accelDate ( date )
297
+ } )
298
+
270
299
suite . add ( 'compile-json-stringify date format' , function ( ) {
271
300
CJSStringifyDate ( date )
272
301
} )
0 commit comments