Skip to content

Add benchmark results to readme #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,43 @@ Scans a given object for prototype properties where:
- `'error'` - throw a `SyntaxError` when a `constructor` key is found. This is the default value.
- `'remove'` - deletes any `constructor` keys from the input `obj`.

## Benchmarks

Machine: 2,7 GHz Quad-Core Intel Core i7

```
v14.8.0

> node ignore.js

JSON.parse x 679,376 ops/sec ±1.15% (84 runs sampled)
secure-json-parse x 649,605 ops/sec ±0.58% (87 runs sampled)
reviver x 244,414 ops/sec ±1.05% (88 runs sampled)
Fastest is JSON.parse

> node no__proto__.js

JSON.parse x 652,190 ops/sec ±0.67% (86 runs sampled)
secure-json-parse x 589,785 ops/sec ±1.01% (88 runs sampled)
reviver x 218,075 ops/sec ±1.58% (87 runs sampled)
Fastest is JSON.parse

> node remove.js

JSON.parse x 683,527 ops/sec ±0.62% (88 runs sampled)
secure-json-parse x 316,926 ops/sec ±0.63% (87 runs sampled)
reviver x 214,167 ops/sec ±0.63% (86 runs sampled)
Fastest is JSON.parse

> node throw.js

JSON.parse x 682,548 ops/sec ±0.60% (88 runs sampled)
JSON.parse error x 170,716 ops/sec ±0.93% (87 runs sampled)
secure-json-parse x 104,483 ops/sec ±0.62% (87 runs sampled)
reviver x 114,197 ops/sec ±0.63% (87 runs sampled)
Fastest is JSON.parse
```

# Acknowledgements
This project has been forked from [hapijs/bourne](https://github.com/hapijs/bourne).
All the credits before the commit [4690682](https://github.com/hapijs/bourne/commit/4690682c6cdaa06590da7b2485d5df91c09da889) goes to the hapijs/bourne project contributors.
Expand Down
6 changes: 3 additions & 3 deletions benchmarks/ignore.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

const Benchmark = require('benchmark')
const Bourne = require('..')
const sjson = require('..')

const internals = {
text: '{ "a": 5, "b": 6, "__proto__": { "x": 7 }, "c": { "d": 0, "e": "text", "__proto__": { "y": 8 }, "f": { "g": 2 } } }'
Expand All @@ -13,8 +13,8 @@ suite
.add('JSON.parse', () => {
JSON.parse(internals.text)
})
.add('Bourne.parse', () => {
Bourne.parse(internals.text, { protoAction: 'ignore' })
.add('secure-json-parse', () => {
sjson.parse(internals.text, { protoAction: 'ignore' })
})
.add('reviver', () => {
JSON.parse(internals.text, internals.reviver)
Expand Down
6 changes: 3 additions & 3 deletions benchmarks/no__proto__.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

const Benchmark = require('benchmark')
const Bourne = require('..')
const sjson = require('..')

const internals = {
text: '{ "a": 5, "b": 6, "proto": { "x": 7 }, "c": { "d": 0, "e": "text", "\\u005f\\u005fproto": { "y": 8 }, "f": { "g": 2 } } }',
Expand All @@ -14,8 +14,8 @@ suite
.add('JSON.parse', () => {
JSON.parse(internals.text)
})
.add('Bourne.parse', () => {
Bourne.parse(internals.text)
.add('secure-json-parse', () => {
sjson.parse(internals.text)
})
.add('reviver', () => {
JSON.parse(internals.text, internals.reviver)
Expand Down
14 changes: 14 additions & 0 deletions benchmarks/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "benchmarks",
"version": "1.0.0",
"scripts": {
"ignore": "node ignore.js",
"no_proto": "node no__proto__.js",
"remove": "node remove.js",
"throw": "node throw.js",
"all": "node --version && npm run ignore && npm run no_proto && npm run remove && npm run throw"
},
"dependencies": {
"benchmark": "^2.1.4"
}
}
6 changes: 3 additions & 3 deletions benchmarks/remove.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

const Benchmark = require('benchmark')
const Bourne = require('..')
const sjson = require('..')

const internals = {
text: '{ "a": 5, "b": 6, "__proto__": { "x": 7 }, "c": { "d": 0, "e": "text", "__proto__": { "y": 8 }, "f": { "g": 2 } } }'
Expand All @@ -13,8 +13,8 @@ suite
.add('JSON.parse', () => {
JSON.parse(internals.text)
})
.add('Bourne.parse', () => {
Bourne.parse(internals.text, { protoAction: 'remove' })
.add('secure-json-parse', () => {
sjson.parse(internals.text, { protoAction: 'remove' })
})
.add('reviver', () => {
JSON.parse(internals.text, internals.reviver)
Expand Down
6 changes: 3 additions & 3 deletions benchmarks/throw.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

const Benchmark = require('benchmark')
const Bourne = require('..')
const sjson = require('..')

const internals = {
text: '{ "a": 5, "b": 6, "__proto__": { "x": 7 }, "c": { "d": 0, "e": "text", "__proto__": { "y": 8 }, "f": { "g": 2 } } }',
Expand All @@ -19,9 +19,9 @@ suite
JSON.parse(internals.invalid)
} catch (ignoreErr) { }
})
.add('Bourne.parse', () => {
.add('secure-json-parse', () => {
try {
Bourne.parse(internals.text)
sjson.parse(internals.text)
} catch (ignoreErr) { }
})
.add('reviver', () => {
Expand Down