You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+5-7Lines changed: 5 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -268,15 +268,13 @@ If you want to retain comments or whitespace for pretty-printing, for example, s
268
268
269
269
### Performance
270
270
271
-
This is a part of an output from the [parser benchmark], when parsing a 4.2 KB formatted string ([package.json](./package.json)) with Node.js 10.15.3:
271
+
This is a part of an output from the [parser benchmark], when parsing a 4.2 KB formatted string ([package.json](./package.json)) with Node.js 12.14.0:
272
272
273
-
the built-in parser x 68,212 ops/sec ±0.86% (87 runs sampled)
274
-
the pure jju parser x 10,234 ops/sec ±1.08% (89 runs sampled)
275
-
the extended jju parser x 10,210 ops/sec ±1.26% (88 runs sampled)
276
-
the tokenizable jju parser x 8,832 ops/sec ±0.92% (89 runs sampled)
277
-
the tokenizing jju parser x 7,911 ops/sec ±1.05% (86 runs sampled)
273
+
jsonlint using native JSON.parse x 97,109 ops/sec ±0.81% (93 runs sampled)
274
+
jsonlint using hand-coded parser x 7,256 ops/sec ±0.54% (90 runs sampled)
275
+
jsonlint using tokenising parser x 6,387 ops/sec ±0.44% (88 runs sampled)
278
276
279
-
A custom JSON parser is [a lot slower] than the built-in one. However, it is more important to have a [clear error reporting] than the highest speed in scenarios like parsing configuration files. Extending the parser with the support for comments and single-quoted strings does not affect the performance. Making the parser collect tokens and their locations decreases the performance a bit.
277
+
A custom JSON parser is [a lot slower] than the built-in one. However, it is more important to have a [clear error reporting] than the highest speed in scenarios like parsing configuration files. (For better error-reporting, the speed can be preserved by using the native parser initially and re-parsing with another parser only in case of failure.) Features like comments or JSON5 are also helpful in configuration files. Tokens preserve the complete input and can be used for pretty-printing without losing the comments.
Copy file name to clipboardExpand all lines: benchmarks/results/performance.md
+35-17Lines changed: 35 additions & 17 deletions
Original file line number
Diff line number
Diff line change
@@ -27,23 +27,27 @@ Results
27
27
28
28
This is a result of the [benchmark] run by `npm run benchmarks`. The numbers should be understood as relative ones:
29
29
30
-
Parsing JSON data 4479 characters long using:
31
-
the built-in parser x 67,113 ops/sec ±0.79% (89 runs sampled)
32
-
the pure chevrotain parser x 15,446 ops/sec ±1.30% (90 runs sampled)
33
-
the extended chevrotain parser x 14,168 ops/sec ±1.23% (88 runs sampled)
34
-
the pure hand-built parser x 9,755 ops/sec ±0.92% (89 runs sampled)
35
-
the extended hand-built parser x 9,633 ops/sec ±1.13% (88 runs sampled)
36
-
the AST parser x 9,768 ops/sec ±0.83% (89 runs sampled)
37
-
the pure jju parser x 10,178 ops/sec ±0.97% (84 runs sampled)
38
-
the extended jju parser x 10,204 ops/sec ±1.13% (88 runs sampled)
39
-
the tokenisable jju parser x 8,904 ops/sec ±1.01% (88 runs sampled)
40
-
the tokenising jju parser x 6,750 ops/sec ±0.97% (88 runs sampled)
41
-
the pure pegjs parser x 3,083 ops/sec ±0.95% (89 runs sampled)
42
-
the extended pegjs parser x 2,786 ops/sec ±1.12% (89 runs sampled)
43
-
the pure jison parser x 3,033 ops/sec ±1.19% (88 runs sampled)
44
-
the extended jison parser x 2,810 ops/sec ±0.65% (88 runs sampled)
45
-
the JSON5 parser x 2,085 ops/sec ±0.45% (91 runs sampled)
46
-
The fastest one was the built-in parser.
30
+
Parsing JSON data 4589 characters long using:
31
+
the built-in parser x 97,039 ops/sec ±0.69% (92 runs sampled)
32
+
the pure chevrotain parser x 11,981 ops/sec ±0.86% (87 runs sampled)
33
+
the extended chevrotain parser x 11,183 ops/sec ±0.54% (88 runs sampled)
34
+
the standard jsonlint parser x 97,109 ops/sec ±0.81% (93 runs sampled)
35
+
the extended jsonlint parser x 7,256 ops/sec ±0.54% (90 runs sampled)
36
+
the tokenising jsonlint parser x 6,387 ops/sec ±0.44% (88 runs sampled)
37
+
the pure hand-built parser x 7,508 ops/sec ±0.49% (86 runs sampled)
38
+
the extended hand-built parser x 7,517 ops/sec ±0.45% (90 runs sampled)
39
+
the AST parser x 8,008 ops/sec ±0.90% (85 runs sampled)
40
+
the pure jju parser x 7,505 ops/sec ±0.64% (89 runs sampled)
41
+
the extended jju parser x 7,352 ops/sec ±0.45% (90 runs sampled)
42
+
the tokenisable jju parser x 6,636 ops/sec ±0.46% (89 runs sampled)
43
+
the tokenising jju parser x 5,373 ops/sec ±0.54% (89 runs sampled)
44
+
the comments-enabled parser x 6,258 ops/sec ±0.95% (88 runs sampled)
45
+
the pure pegjs parser x 2,803 ops/sec ±0.58% (88 runs sampled)
46
+
the extended pegjs parser x 2,526 ops/sec ±0.74% (87 runs sampled)
47
+
the pure jison parser x 2,460 ops/sec ±0.49% (89 runs sampled)
48
+
the extended jison parser x 2,195 ops/sec ±0.63% (88 runs sampled)
49
+
the JSON5 parser x 1,660 ops/sec ±0.84% (90 runs sampled)
50
+
The fastest one was the built-in parser,the standard jsonlint parser.
47
51
48
52
I looked further at capabilities and licenses of the parsers.
49
53
@@ -86,6 +90,13 @@ I looked further at capabilities and licenses of the parsers.
86
90
* Supports `reviver` for the full compatibility with JSON.parse.
87
91
* Can generate tokens to analyse, modify and update the original JSON input.
88
92
93
+
[comment-json]
94
+
--------------
95
+
96
+
* Very fast one.
97
+
* Supports `reviver` for the full compatibility with JSON.parse.
98
+
* Supports CJSON - JSON with JavaScript-like comments.
99
+
89
100
[PEG.JS]
90
101
--------
91
102
@@ -105,13 +116,20 @@ I looked further at capabilities and licenses of the parsers.
105
116
* Hand-built parser implementing the [JSON5 specification]. Extensions mentioned above were included, and even more, like trailing commas or multi-line strings. No support for pure JSON.
106
117
* Slower one.
107
118
119
+
[JSONLint]
120
+
----------
121
+
122
+
This entry is here just to compare the current implementation to the original "contenders". Based on the [evaluation] results, the current JSONLint uses a hand-coded parser based on [JJU].
123
+
108
124
[tested with a JSON grammar]: https://sap.github.io/chevrotain/performance/
109
125
[quality of error reporting]: ./errorReportingQuality.md
0 commit comments