Skip to content

Commit b062cdb

Browse files
Add benchmark results to readme (#9)
* Add benchmark results to readme #3 * Update Bourne references
1 parent 07574d6 commit b062cdb

File tree

6 files changed

+63
-12
lines changed

6 files changed

+63
-12
lines changed

README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,43 @@ Scans a given object for prototype properties where:
7979
- `'error'` - throw a `SyntaxError` when a `constructor` key is found. This is the default value.
8080
- `'remove'` - deletes any `constructor` keys from the input `obj`.
8181

82+
## Benchmarks
83+
84+
Machine: 2,7 GHz Quad-Core Intel Core i7
85+
86+
```
87+
v14.8.0
88+
89+
> node ignore.js
90+
91+
JSON.parse x 679,376 ops/sec ±1.15% (84 runs sampled)
92+
secure-json-parse x 649,605 ops/sec ±0.58% (87 runs sampled)
93+
reviver x 244,414 ops/sec ±1.05% (88 runs sampled)
94+
Fastest is JSON.parse
95+
96+
> node no__proto__.js
97+
98+
JSON.parse x 652,190 ops/sec ±0.67% (86 runs sampled)
99+
secure-json-parse x 589,785 ops/sec ±1.01% (88 runs sampled)
100+
reviver x 218,075 ops/sec ±1.58% (87 runs sampled)
101+
Fastest is JSON.parse
102+
103+
> node remove.js
104+
105+
JSON.parse x 683,527 ops/sec ±0.62% (88 runs sampled)
106+
secure-json-parse x 316,926 ops/sec ±0.63% (87 runs sampled)
107+
reviver x 214,167 ops/sec ±0.63% (86 runs sampled)
108+
Fastest is JSON.parse
109+
110+
> node throw.js
111+
112+
JSON.parse x 682,548 ops/sec ±0.60% (88 runs sampled)
113+
JSON.parse error x 170,716 ops/sec ±0.93% (87 runs sampled)
114+
secure-json-parse x 104,483 ops/sec ±0.62% (87 runs sampled)
115+
reviver x 114,197 ops/sec ±0.63% (87 runs sampled)
116+
Fastest is JSON.parse
117+
```
118+
82119
# Acknowledgements
83120
This project has been forked from [hapijs/bourne](https://github.com/hapijs/bourne).
84121
All the credits before the commit [4690682](https://github.com/hapijs/bourne/commit/4690682c6cdaa06590da7b2485d5df91c09da889) goes to the hapijs/bourne project contributors.

benchmarks/ignore.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict'
22

33
const Benchmark = require('benchmark')
4-
const Bourne = require('..')
4+
const sjson = require('..')
55

66
const internals = {
77
text: '{ "a": 5, "b": 6, "__proto__": { "x": 7 }, "c": { "d": 0, "e": "text", "__proto__": { "y": 8 }, "f": { "g": 2 } } }'
@@ -13,8 +13,8 @@ suite
1313
.add('JSON.parse', () => {
1414
JSON.parse(internals.text)
1515
})
16-
.add('Bourne.parse', () => {
17-
Bourne.parse(internals.text, { protoAction: 'ignore' })
16+
.add('secure-json-parse', () => {
17+
sjson.parse(internals.text, { protoAction: 'ignore' })
1818
})
1919
.add('reviver', () => {
2020
JSON.parse(internals.text, internals.reviver)

benchmarks/no__proto__.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict'
22

33
const Benchmark = require('benchmark')
4-
const Bourne = require('..')
4+
const sjson = require('..')
55

66
const internals = {
77
text: '{ "a": 5, "b": 6, "proto": { "x": 7 }, "c": { "d": 0, "e": "text", "\\u005f\\u005fproto": { "y": 8 }, "f": { "g": 2 } } }',
@@ -14,8 +14,8 @@ suite
1414
.add('JSON.parse', () => {
1515
JSON.parse(internals.text)
1616
})
17-
.add('Bourne.parse', () => {
18-
Bourne.parse(internals.text)
17+
.add('secure-json-parse', () => {
18+
sjson.parse(internals.text)
1919
})
2020
.add('reviver', () => {
2121
JSON.parse(internals.text, internals.reviver)

benchmarks/package.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "benchmarks",
3+
"version": "1.0.0",
4+
"scripts": {
5+
"ignore": "node ignore.js",
6+
"no_proto": "node no__proto__.js",
7+
"remove": "node remove.js",
8+
"throw": "node throw.js",
9+
"all": "node --version && npm run ignore && npm run no_proto && npm run remove && npm run throw"
10+
},
11+
"dependencies": {
12+
"benchmark": "^2.1.4"
13+
}
14+
}

benchmarks/remove.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict'
22

33
const Benchmark = require('benchmark')
4-
const Bourne = require('..')
4+
const sjson = require('..')
55

66
const internals = {
77
text: '{ "a": 5, "b": 6, "__proto__": { "x": 7 }, "c": { "d": 0, "e": "text", "__proto__": { "y": 8 }, "f": { "g": 2 } } }'
@@ -13,8 +13,8 @@ suite
1313
.add('JSON.parse', () => {
1414
JSON.parse(internals.text)
1515
})
16-
.add('Bourne.parse', () => {
17-
Bourne.parse(internals.text, { protoAction: 'remove' })
16+
.add('secure-json-parse', () => {
17+
sjson.parse(internals.text, { protoAction: 'remove' })
1818
})
1919
.add('reviver', () => {
2020
JSON.parse(internals.text, internals.reviver)

benchmarks/throw.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict'
22

33
const Benchmark = require('benchmark')
4-
const Bourne = require('..')
4+
const sjson = require('..')
55

66
const internals = {
77
text: '{ "a": 5, "b": 6, "__proto__": { "x": 7 }, "c": { "d": 0, "e": "text", "__proto__": { "y": 8 }, "f": { "g": 2 } } }',
@@ -19,9 +19,9 @@ suite
1919
JSON.parse(internals.invalid)
2020
} catch (ignoreErr) { }
2121
})
22-
.add('Bourne.parse', () => {
22+
.add('secure-json-parse', () => {
2323
try {
24-
Bourne.parse(internals.text)
24+
sjson.parse(internals.text)
2525
} catch (ignoreErr) { }
2626
})
2727
.add('reviver', () => {

0 commit comments

Comments
 (0)