fast-json-stringify 6.0.1 → 6.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/ci.yml +6 -1
- package/LICENSE +5 -2
- package/README.md +36 -31
- package/benchmark/bench-cmp-branch.js +1 -1
- package/benchmark/bench-cmp-lib.js +29 -0
- package/index.js +34 -16
- package/lib/serializer.js +4 -5
- package/package.json +4 -8
- package/test/json-schema-test-suite/README.md +1 -1
- package/.github/workflows/benchmark.yml +0 -85
package/.github/workflows/ci.yml
CHANGED
|
@@ -4,7 +4,6 @@ on:
|
|
|
4
4
|
push:
|
|
5
5
|
branches:
|
|
6
6
|
- main
|
|
7
|
-
- master
|
|
8
7
|
- next
|
|
9
8
|
- 'v*'
|
|
10
9
|
paths-ignore:
|
|
@@ -15,8 +14,14 @@ on:
|
|
|
15
14
|
- 'docs/**'
|
|
16
15
|
- '*.md'
|
|
17
16
|
|
|
17
|
+
permissions:
|
|
18
|
+
contents: read
|
|
19
|
+
|
|
18
20
|
jobs:
|
|
19
21
|
test:
|
|
22
|
+
permissions:
|
|
23
|
+
contents: write
|
|
24
|
+
pull-requests: write
|
|
20
25
|
uses: fastify/workflows/.github/workflows/plugins-ci.yml@v5
|
|
21
26
|
with:
|
|
22
27
|
license-check: true
|
package/LICENSE
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2016-
|
|
3
|
+
Copyright (c) 2016-present Matteo Collina
|
|
4
|
+
Copyright (c) 2016-present The Fastify team
|
|
5
|
+
|
|
6
|
+
The Fastify team members are listed at https://github.com/fastify/fastify#team.
|
|
4
7
|
|
|
5
8
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
9
|
of this software and associated documentation files (the "Software"), to deal
|
package/README.md
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
# fast-json-stringify
|
|
2
2
|
|
|
3
|
-
[](https://github.com/fastify/fast-json-stringify/actions/workflows/ci.yml)
|
|
4
4
|
[](https://www.npmjs.com/package/fast-json-stringify)
|
|
5
5
|
[](https://github.com/neostandard/neostandard)
|
|
6
6
|
[](https://www.npmjs.com/package/fast-json-stringify)
|
|
7
7
|
|
|
8
|
-
|
|
9
8
|
__fast-json-stringify__ is significantly faster than `JSON.stringify()` for small payloads.
|
|
10
9
|
Its performance advantage shrinks as your payload grows.
|
|
11
10
|
It pairs well with [__flatstr__](https://www.npmjs.com/package/flatstr), which triggers a V8 optimization that improves performance when eventually converting the string to a `Buffer`.
|
|
@@ -18,37 +17,43 @@ fast-json-stringify requires a [JSON Schema Draft 7](https://json-schema.org/spe
|
|
|
18
17
|
##### Benchmarks
|
|
19
18
|
|
|
20
19
|
- Machine: `EX41S-SSD, Intel Core i7, 4Ghz, 64GB RAM, 4C/8T, SSD`.
|
|
21
|
-
- Node.js `
|
|
20
|
+
- Node.js `v22.14.0`
|
|
22
21
|
|
|
23
22
|
```
|
|
24
|
-
FJS creation x
|
|
25
|
-
CJS creation x
|
|
26
|
-
AJV Serialize creation x
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
fast-json-stringify array
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
compile-json-stringify
|
|
48
|
-
AJV Serialize
|
|
49
|
-
JSON
|
|
50
|
-
fast-json-stringify
|
|
51
|
-
|
|
23
|
+
FJS creation x 9,696 ops/sec ±0.77% (94 runs sampled)
|
|
24
|
+
CJS creation x 197,267 ops/sec ±0.22% (95 runs sampled)
|
|
25
|
+
AJV Serialize creation x 48,302,927 ops/sec ±2.09% (90 runs sampled)
|
|
26
|
+
json-accelerator creation x 668,430 ops/sec ±0.43% (95 runs sampled)
|
|
27
|
+
JSON.stringify array x 7,924 ops/sec ±0.11% (98 runs sampled)
|
|
28
|
+
fast-json-stringify array default x 7,183 ops/sec ±0.09% (97 runs sampled)
|
|
29
|
+
json-accelerator array x 5,762 ops/sec ±0.27% (99 runs sampled)
|
|
30
|
+
fast-json-stringify array json-stringify x 7,171 ops/sec ±0.17% (97 runs sampled)
|
|
31
|
+
compile-json-stringify array x 6,889 ops/sec ±0.41% (96 runs sampled)
|
|
32
|
+
AJV Serialize array x 6,945 ops/sec ±0.17% (98 runs sampled)
|
|
33
|
+
JSON.stringify large array x 331 ops/sec ±0.17% (93 runs sampled)
|
|
34
|
+
fast-json-stringify large array default x 208 ops/sec ±0.21% (91 runs sampled)
|
|
35
|
+
fast-json-stringify large array json-stringify x 330 ops/sec ±0.17% (93 runs sampled)
|
|
36
|
+
compile-json-stringify large array x 318 ops/sec ±0.11% (90 runs sampled)
|
|
37
|
+
AJV Serialize large array x 114 ops/sec ±0.27% (74 runs sampled)
|
|
38
|
+
JSON.stringify long string x 13,452 ops/sec ±0.15% (99 runs sampled)
|
|
39
|
+
fast-json-stringify long string x 13,454 ops/sec ±0.10% (99 runs sampled)
|
|
40
|
+
json-accelerator long string x 13,439 ops/sec ±0.09% (98 runs sampled)
|
|
41
|
+
compile-json-stringify long string x 13,380 ops/sec ±0.12% (100 runs sampled)
|
|
42
|
+
AJV Serialize long string x 21,932 ops/sec ±0.06% (99 runs sampled)
|
|
43
|
+
JSON.stringify short string x 12,114,052 ops/sec ±0.59% (97 runs sampled)
|
|
44
|
+
fast-json-stringify short string x 29,408,175 ops/sec ±1.12% (91 runs sampled)
|
|
45
|
+
json-accelerator short string x 29,431,694 ops/sec ±1.05% (93 runs sampled)
|
|
46
|
+
compile-json-stringify short string x 24,740,338 ops/sec ±1.02% (91 runs sampled)
|
|
47
|
+
AJV Serialize short string x 17,841,869 ops/sec ±0.90% (91 runs sampled)
|
|
48
|
+
JSON.stringify obj x 4,577,494 ops/sec ±0.25% (94 runs sampled)
|
|
49
|
+
fast-json-stringify obj x 7,291,157 ops/sec ±0.40% (97 runs sampled)
|
|
50
|
+
json-accelerator obj x 6,473,194 ops/sec ±0.31% (99 runs sampled)
|
|
51
|
+
compile-json-stringify obj x 14,724,935 ops/sec ±0.50% (96 runs sampled)
|
|
52
|
+
AJV Serialize obj x 8,782,944 ops/sec ±0.45% (93 runs sampled)
|
|
53
|
+
JSON stringify date x 803,522 ops/sec ±0.47% (98 runs sampled)
|
|
54
|
+
fast-json-stringify date format x 1,117,776 ops/sec ±0.69% (95 runs sampled)
|
|
55
|
+
json-accelerate date format x 1,122,419 ops/sec ±0.20% (97 runs sampled)
|
|
56
|
+
compile-json-stringify date format x 803,214 ops/sec ±0.23% (97 runs sampled)
|
|
52
57
|
```
|
|
53
58
|
|
|
54
59
|
#### Table of contents:
|
|
@@ -8,7 +8,7 @@ const simpleGit = require('simple-git')
|
|
|
8
8
|
const git = simpleGit(process.cwd())
|
|
9
9
|
|
|
10
10
|
const COMMAND = 'npm run bench'
|
|
11
|
-
const DEFAULT_BRANCH = '
|
|
11
|
+
const DEFAULT_BRANCH = 'main'
|
|
12
12
|
const PERCENT_THRESHOLD = 5
|
|
13
13
|
const greyColor = '\x1b[30m'
|
|
14
14
|
const redColor = '\x1b[31m'
|
|
@@ -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
|
})
|
package/index.js
CHANGED
|
@@ -15,6 +15,21 @@ const SINGLE_TICK = /'/g
|
|
|
15
15
|
let largeArraySize = 2e4
|
|
16
16
|
let largeArrayMechanism = 'default'
|
|
17
17
|
|
|
18
|
+
const serializerFns = `
|
|
19
|
+
const {
|
|
20
|
+
asString,
|
|
21
|
+
asNumber,
|
|
22
|
+
asBoolean,
|
|
23
|
+
asDateTime,
|
|
24
|
+
asDate,
|
|
25
|
+
asTime,
|
|
26
|
+
asUnsafeString
|
|
27
|
+
} = serializer
|
|
28
|
+
|
|
29
|
+
const asInteger = serializer.asInteger.bind(serializer)
|
|
30
|
+
|
|
31
|
+
`
|
|
32
|
+
|
|
18
33
|
const validRoundingMethods = [
|
|
19
34
|
'floor',
|
|
20
35
|
'ceil',
|
|
@@ -141,6 +156,7 @@ function build (schema, options) {
|
|
|
141
156
|
const code = buildValue(context, location, 'input')
|
|
142
157
|
|
|
143
158
|
let contextFunctionCode = `
|
|
159
|
+
${serializerFns}
|
|
144
160
|
const JSON_STR_BEGIN_OBJECT = '{'
|
|
145
161
|
const JSON_STR_END_OBJECT = '}'
|
|
146
162
|
const JSON_STR_BEGIN_ARRAY = '['
|
|
@@ -292,7 +308,7 @@ function buildExtraObjectPropertiesSerializer (context, location, addComma) {
|
|
|
292
308
|
code += `
|
|
293
309
|
if (/${propertyKey.replace(/\\*\//g, '\\/')}/.test(key)) {
|
|
294
310
|
${addComma}
|
|
295
|
-
json +=
|
|
311
|
+
json += asString(key) + JSON_STR_COLONS
|
|
296
312
|
${buildValue(context, propertyLocation, 'value')}
|
|
297
313
|
continue
|
|
298
314
|
}
|
|
@@ -307,13 +323,13 @@ function buildExtraObjectPropertiesSerializer (context, location, addComma) {
|
|
|
307
323
|
if (additionalPropertiesSchema === true) {
|
|
308
324
|
code += `
|
|
309
325
|
${addComma}
|
|
310
|
-
json +=
|
|
326
|
+
json += asString(key) + JSON_STR_COLONS + JSON.stringify(value)
|
|
311
327
|
`
|
|
312
328
|
} else {
|
|
313
329
|
const propertyLocation = location.getPropertyLocation('additionalProperties')
|
|
314
330
|
code += `
|
|
315
331
|
${addComma}
|
|
316
|
-
json +=
|
|
332
|
+
json += asString(key) + JSON_STR_COLONS
|
|
317
333
|
${buildValue(context, propertyLocation, 'value')}
|
|
318
334
|
`
|
|
319
335
|
}
|
|
@@ -565,7 +581,7 @@ function buildArray (context, location) {
|
|
|
565
581
|
const tmpRes = buildValue(context, itemsLocation.getPropertyLocation(i), 'value')
|
|
566
582
|
functionCode += `
|
|
567
583
|
if (${i} < arrayLength) {
|
|
568
|
-
if (${buildArrayTypeCondition(item.type,
|
|
584
|
+
if (${buildArrayTypeCondition(item.type, 'value')}) {
|
|
569
585
|
${tmpRes}
|
|
570
586
|
if (${i} < arrayEnd) {
|
|
571
587
|
json += JSON_STR_COMMA
|
|
@@ -580,16 +596,18 @@ function buildArray (context, location) {
|
|
|
580
596
|
if (schema.additionalItems) {
|
|
581
597
|
functionCode += `
|
|
582
598
|
for (let i = ${itemsSchema.length}; i < arrayLength; i++) {
|
|
583
|
-
|
|
599
|
+
value = obj[i]
|
|
600
|
+
json += JSON.stringify(value)
|
|
584
601
|
if (i < arrayEnd) {
|
|
585
602
|
json += JSON_STR_COMMA
|
|
586
603
|
}
|
|
587
604
|
}`
|
|
588
605
|
}
|
|
589
606
|
} else {
|
|
590
|
-
const code = buildValue(context, itemsLocation, '
|
|
607
|
+
const code = buildValue(context, itemsLocation, 'value')
|
|
591
608
|
functionCode += `
|
|
592
609
|
for (let i = 0; i < arrayLength; i++) {
|
|
610
|
+
value = obj[i]
|
|
593
611
|
${code}
|
|
594
612
|
if (i < arrayEnd) {
|
|
595
613
|
json += JSON_STR_COMMA
|
|
@@ -729,13 +747,13 @@ function buildSingleTypeSerializer (context, location, input) {
|
|
|
729
747
|
return 'json += JSON_STR_NULL'
|
|
730
748
|
case 'string': {
|
|
731
749
|
if (schema.format === 'date-time') {
|
|
732
|
-
return `json +=
|
|
750
|
+
return `json += asDateTime(${input})`
|
|
733
751
|
} else if (schema.format === 'date') {
|
|
734
|
-
return `json +=
|
|
752
|
+
return `json += asDate(${input})`
|
|
735
753
|
} else if (schema.format === 'time') {
|
|
736
|
-
return `json +=
|
|
754
|
+
return `json += asTime(${input})`
|
|
737
755
|
} else if (schema.format === 'unsafe') {
|
|
738
|
-
return `json +=
|
|
756
|
+
return `json += asUnsafeString(${input})`
|
|
739
757
|
} else {
|
|
740
758
|
return `
|
|
741
759
|
if (typeof ${input} !== 'string') {
|
|
@@ -744,22 +762,22 @@ function buildSingleTypeSerializer (context, location, input) {
|
|
|
744
762
|
} else if (${input} instanceof Date) {
|
|
745
763
|
json += JSON_STR_QUOTE + ${input}.toISOString() + JSON_STR_QUOTE
|
|
746
764
|
} else if (${input} instanceof RegExp) {
|
|
747
|
-
json +=
|
|
765
|
+
json += asString(${input}.source)
|
|
748
766
|
} else {
|
|
749
|
-
json +=
|
|
767
|
+
json += asString(${input}.toString())
|
|
750
768
|
}
|
|
751
769
|
} else {
|
|
752
|
-
json +=
|
|
770
|
+
json += asString(${input})
|
|
753
771
|
}
|
|
754
772
|
`
|
|
755
773
|
}
|
|
756
774
|
}
|
|
757
775
|
case 'integer':
|
|
758
|
-
return `json +=
|
|
776
|
+
return `json += asInteger(${input})`
|
|
759
777
|
case 'number':
|
|
760
|
-
return `json +=
|
|
778
|
+
return `json += asNumber(${input})`
|
|
761
779
|
case 'boolean':
|
|
762
|
-
return `json +=
|
|
780
|
+
return `json += asBoolean(${input})`
|
|
763
781
|
case 'object': {
|
|
764
782
|
const funcName = buildObject(context, location)
|
|
765
783
|
return `json += ${funcName}(${input})`
|
package/lib/serializer.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
// eslint-disable-next-line
|
|
4
|
-
const STR_ESCAPE = /[\u0000-\u001f\u0022\u005c\ud800-\udfff]/
|
|
5
|
-
|
|
6
3
|
module.exports = class Serializer {
|
|
7
4
|
constructor (options) {
|
|
8
5
|
switch (options && options.rounding) {
|
|
@@ -92,7 +89,9 @@ module.exports = class Serializer {
|
|
|
92
89
|
|
|
93
90
|
asString (str) {
|
|
94
91
|
const len = str.length
|
|
95
|
-
if (len
|
|
92
|
+
if (len === 0) {
|
|
93
|
+
return '""'
|
|
94
|
+
} else if (len < 42) {
|
|
96
95
|
// magically escape strings for json
|
|
97
96
|
// relying on their charCodeAt
|
|
98
97
|
// everything below 32 needs JSON.stringify()
|
|
@@ -117,7 +116,7 @@ module.exports = class Serializer {
|
|
|
117
116
|
}
|
|
118
117
|
}
|
|
119
118
|
return (last === -1 && ('"' + str + '"')) || ('"' + result + str.slice(last) + '"')
|
|
120
|
-
} else if (len < 5000 &&
|
|
119
|
+
} else if (len < 5000 && str.isWellFormed()) {
|
|
121
120
|
// Only use the regular expression for shorter input. The overhead is otherwise too much.
|
|
122
121
|
return '"' + str + '"'
|
|
123
122
|
} else {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fast-json-stringify",
|
|
3
|
-
"version": "6.0
|
|
3
|
+
"version": "6.1.0",
|
|
4
4
|
"description": "Stringify your JSON at max speed",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "commonjs",
|
|
@@ -16,10 +16,6 @@
|
|
|
16
16
|
"test:unit": "c8 node --test",
|
|
17
17
|
"test": "npm run test:unit && npm run test:typescript"
|
|
18
18
|
},
|
|
19
|
-
"precommit": [
|
|
20
|
-
"lint",
|
|
21
|
-
"test"
|
|
22
|
-
],
|
|
23
19
|
"repository": {
|
|
24
20
|
"type": "git",
|
|
25
21
|
"url": "git+https://github.com/fastify/fast-json-stringify.git"
|
|
@@ -66,7 +62,6 @@
|
|
|
66
62
|
}
|
|
67
63
|
],
|
|
68
64
|
"devDependencies": {
|
|
69
|
-
"@fastify/pre-commit": "^2.1.0",
|
|
70
65
|
"@sinclair/typebox": "^0.34.3",
|
|
71
66
|
"benchmark": "^2.1.4",
|
|
72
67
|
"c8": "^10.1.2",
|
|
@@ -75,9 +70,10 @@
|
|
|
75
70
|
"eslint": "^9.17.0",
|
|
76
71
|
"fast-json-stringify": ".",
|
|
77
72
|
"is-my-json-valid": "^2.20.6",
|
|
73
|
+
"json-accelerator": "^0.0.2",
|
|
78
74
|
"neostandard": "^0.12.0",
|
|
79
75
|
"simple-git": "^3.23.0",
|
|
80
|
-
"tsd": "^0.
|
|
76
|
+
"tsd": "^0.32.0",
|
|
81
77
|
"webpack": "^5.90.3"
|
|
82
78
|
},
|
|
83
79
|
"dependencies": {
|
|
@@ -85,7 +81,7 @@
|
|
|
85
81
|
"ajv": "^8.12.0",
|
|
86
82
|
"ajv-formats": "^3.0.1",
|
|
87
83
|
"fast-uri": "^3.0.0",
|
|
88
|
-
"json-schema-ref-resolver": "^
|
|
84
|
+
"json-schema-ref-resolver": "^3.0.0",
|
|
89
85
|
"rfdc": "^1.2.0"
|
|
90
86
|
},
|
|
91
87
|
"runkitExampleFilename": "./examples/example.js"
|
|
@@ -5,6 +5,6 @@ It contains a set of JSON objects that implementors of JSON Schema validation li
|
|
|
5
5
|
|
|
6
6
|
# How to add another test case?
|
|
7
7
|
|
|
8
|
-
1. Navigate to [JSON-Schema-Test-Suite](https://github.com/json-schema-org/JSON-Schema-Test-Suite/tree/
|
|
8
|
+
1. Navigate to [JSON-Schema-Test-Suite](https://github.com/json-schema-org/JSON-Schema-Test-Suite/tree/main/tests)
|
|
9
9
|
2. Choose a draft `draft4`, `draft6` or `draft7`
|
|
10
10
|
3. Copy & paste the `test-case.json` to the project and add a test like in the `draft4.test.js`
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
name: Benchmark PR
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
pull_request_target:
|
|
5
|
-
types: [labeled]
|
|
6
|
-
|
|
7
|
-
jobs:
|
|
8
|
-
benchmark:
|
|
9
|
-
if: ${{ github.event.label.name == 'benchmark' }}
|
|
10
|
-
runs-on: ubuntu-latest
|
|
11
|
-
permissions:
|
|
12
|
-
contents: read
|
|
13
|
-
outputs:
|
|
14
|
-
PR-BENCH: ${{ steps.benchmark-pr.outputs.BENCH_RESULT }}
|
|
15
|
-
MASTER-BENCH: ${{ steps.benchmark-master.outputs.BENCH_RESULT }}
|
|
16
|
-
steps:
|
|
17
|
-
- uses: actions/checkout@v4
|
|
18
|
-
with:
|
|
19
|
-
persist-credentials: false
|
|
20
|
-
ref: ${{github.event.pull_request.head.sha}}
|
|
21
|
-
repository: ${{github.event.pull_request.head.repo.full_name}}
|
|
22
|
-
|
|
23
|
-
- uses: actions/setup-node@v4
|
|
24
|
-
with:
|
|
25
|
-
node-version: 18
|
|
26
|
-
|
|
27
|
-
- name: Install
|
|
28
|
-
run: |
|
|
29
|
-
npm install --ignore-scripts
|
|
30
|
-
|
|
31
|
-
- name: Run benchmark
|
|
32
|
-
id: benchmark-pr
|
|
33
|
-
run: |
|
|
34
|
-
npm run --silent bench > ./bench-result
|
|
35
|
-
content=$(cat ./bench-result)
|
|
36
|
-
content="${content//'%'/'%25'}"
|
|
37
|
-
content="${content//$'\n'/'%0A'}"
|
|
38
|
-
content="${content//$'\r'/'%0D'}"
|
|
39
|
-
echo "::set-output name=BENCH_RESULT::$content"
|
|
40
|
-
|
|
41
|
-
# master benchmark
|
|
42
|
-
- uses: actions/checkout@v4
|
|
43
|
-
with:
|
|
44
|
-
ref: 'master'
|
|
45
|
-
|
|
46
|
-
- name: Install
|
|
47
|
-
run: |
|
|
48
|
-
npm install --ignore-scripts
|
|
49
|
-
|
|
50
|
-
- name: Run benchmark
|
|
51
|
-
id: benchmark-master
|
|
52
|
-
run: |
|
|
53
|
-
npm run --silent bench > ./bench-result
|
|
54
|
-
content=$(cat ./bench-result)
|
|
55
|
-
content="${content//'%'/'%25'}"
|
|
56
|
-
content="${content//$'\n'/'%0A'}"
|
|
57
|
-
content="${content//$'\r'/'%0D'}"
|
|
58
|
-
echo "::set-output name=BENCH_RESULT::$content"
|
|
59
|
-
|
|
60
|
-
output-benchmark:
|
|
61
|
-
if: "always()"
|
|
62
|
-
needs: [benchmark]
|
|
63
|
-
runs-on: ubuntu-latest
|
|
64
|
-
permissions:
|
|
65
|
-
pull-requests: write
|
|
66
|
-
steps:
|
|
67
|
-
- name: Comment PR
|
|
68
|
-
uses: thollander/actions-comment-pull-request@v3
|
|
69
|
-
with:
|
|
70
|
-
github-token: ${{ secrets.GITHUB_TOKEN }}
|
|
71
|
-
message: |
|
|
72
|
-
**PR**:
|
|
73
|
-
```
|
|
74
|
-
${{ needs.benchmark.outputs.PR-BENCH }}
|
|
75
|
-
```
|
|
76
|
-
**MASTER**:
|
|
77
|
-
```
|
|
78
|
-
${{ needs.benchmark.outputs.MASTER-BENCH }}
|
|
79
|
-
```
|
|
80
|
-
|
|
81
|
-
- uses: actions-ecosystem/action-remove-labels@v1
|
|
82
|
-
with:
|
|
83
|
-
labels: |
|
|
84
|
-
benchmark
|
|
85
|
-
github_token: ${{ secrets.GITHUB_TOKEN }}
|