diff --git a/README.md b/README.md index 6fe57a9..c6d18cf 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/benchmarks/ignore.js b/benchmarks/ignore.js index 2be3947..49c36f8 100755 --- a/benchmarks/ignore.js +++ b/benchmarks/ignore.js @@ -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 } } }' @@ -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) diff --git a/benchmarks/no__proto__.js b/benchmarks/no__proto__.js index fd98554..74763dc 100755 --- a/benchmarks/no__proto__.js +++ b/benchmarks/no__proto__.js @@ -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 } } }', @@ -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) diff --git a/benchmarks/package.json b/benchmarks/package.json new file mode 100644 index 0000000..a6c243e --- /dev/null +++ b/benchmarks/package.json @@ -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" + } +} diff --git a/benchmarks/remove.js b/benchmarks/remove.js index 92a3e1a..cd7ad60 100755 --- a/benchmarks/remove.js +++ b/benchmarks/remove.js @@ -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 } } }' @@ -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) diff --git a/benchmarks/throw.js b/benchmarks/throw.js index 2b5a800..92bcfc2 100755 --- a/benchmarks/throw.js +++ b/benchmarks/throw.js @@ -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 } } }', @@ -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', () => {