Skip to content
This repository was archived by the owner on Mar 6, 2018. It is now read-only.

Commit 1dbe294

Browse files
sonnypSonny Piers
authored andcommitted
benchmark
1 parent 0a925e1 commit 1dbe294

File tree

4 files changed

+90
-0
lines changed

4 files changed

+90
-0
lines changed

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,7 @@ node_js:
1111

1212
before_install:
1313
- npm install mocha browserify
14+
15+
script:
16+
- npm test
17+
- npm run benchmark

benchmark.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
'use strict'
2+
3+
/* eslint-disable no-console */
4+
5+
var benchmark = require('benchmark')
6+
var ooPatch = require('./index')
7+
var jsonpatch = require('jsonpatch') // https://github.com/dharmafly/jsonpatch.js
8+
var json_patch = require('json-patch') // https://github.com/bruth/jsonpatch-js
9+
var jiff = require('jiff') // https://github.com/cujojs/jiff
10+
var fastjsonpatch = require('fast-json-patch') // https://github.com/Starcounter-Jack/JSON-Patch
11+
12+
var doc = {
13+
"foo": [1, 2, 3, 4],
14+
"baz": [{
15+
"qux": "hello",
16+
}],
17+
}
18+
19+
var patch = [{
20+
"op": "replace",
21+
"path": "/baz/0/qux",
22+
"value": "world",
23+
}]
24+
25+
benchmark.Suite('apply patch') // eslint-disable-line
26+
.add('github: json8/patch - npm: json8-patch', function() {
27+
ooPatch.apply(doc, patch)
28+
})
29+
.add('github: dharmafly/jsonpatch.js / npm: jsonpatch', function() {
30+
jsonpatch.apply_patch(doc, patch)
31+
})
32+
.add('github: bruth/jsonpatch-js / npm: json_patch', function() {
33+
json_patch.apply(doc, patch)
34+
})
35+
.add('github: cujojs/jiff / npm: jiff', function() {
36+
jiff.patch(patch, doc)
37+
})
38+
.add('github: Starcounter-Jack/JSON-Patch / npm: fast-json-patch', function() {
39+
fastjsonpatch.apply(doc, patch)
40+
})
41+
.on('cycle', function(event) {
42+
console.log(event.target.toString())
43+
})
44+
.on('complete', function() {
45+
console.log('Fastest is ' + this.filter('fastest').map('name'))
46+
})
47+
.run()

package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"bundle": "browserify -s JSON8Patch index.js -o JSON8Patch.js",
1616
"lint": "eslint .",
1717
"unit": "mocha --compilers js:babel-core/register --recursive test/",
18+
"benchmark": "node benchmark.js",
1819
"test": "npm run unit && npm run lint && npm run bundle"
1920
},
2021
"author": "Sonny Piers <sonny@fastmail.net>",
@@ -26,9 +27,14 @@
2627
"devDependencies": {
2728
"babel-core": "^6.8.0",
2829
"babel-preset-es2015": "^6.3.13",
30+
"benchmark": "^2.1.0",
2931
"browserify": "^15.2.0",
3032
"eslint": "^0.24.1",
33+
"fast-json-patch": "^2.0.6",
34+
"jiff": "^0.7.3",
35+
"json-patch": "^0.7.0",
3136
"json-patch-test-suite": "^1.1.0",
37+
"jsonpatch": "^3.0.1",
3238
"mocha": "^5.0.0"
3339
}
3440
}

yarn.lock

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,13 @@ base64-js@^1.0.2:
479479
version "1.2.1"
480480
resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-1.2.1.tgz#a91947da1f4a516ea38e5b4ec0ec3773675e0886"
481481

482+
benchmark@^2.1.0:
483+
version "2.1.4"
484+
resolved "https://registry.yarnpkg.com/benchmark/-/benchmark-2.1.4.tgz#09f3de31c916425d498cc2ee565a0ebf3c2a5629"
485+
dependencies:
486+
lodash "^4.17.4"
487+
platform "^1.3.3"
488+
482489
bn.js@^4.0.0, bn.js@^4.1.0, bn.js@^4.1.1, bn.js@^4.4.0:
483490
version "4.11.8"
484491
resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-4.11.8.tgz#2cde09eb5ee341f484746bb0309b3253b1b1442f"
@@ -793,6 +800,10 @@ debug@^2.1.1, debug@^2.6.8:
793800
dependencies:
794801
ms "2.0.0"
795802

803+
deep-equal@^1.0.1:
804+
version "1.0.1"
805+
resolved "https://registry.yarnpkg.com/deep-equal/-/deep-equal-1.0.1.tgz#f5d260292b660e084eff4cdbc9f08ad3247448b5"
806+
796807
deep-is@~0.1.2:
797808
version "0.1.3"
798809
resolved "https://registry.yarnpkg.com/deep-is/-/deep-is-0.1.3.tgz#b369d6fb5dbc13eecf524f91b070feedc357cf34"
@@ -1013,6 +1024,12 @@ evp_bytestokey@^1.0.0, evp_bytestokey@^1.0.3:
10131024
md5.js "^1.3.4"
10141025
safe-buffer "^5.1.1"
10151026

1027+
fast-json-patch@^2.0.6:
1028+
version "2.0.6"
1029+
resolved "https://registry.yarnpkg.com/fast-json-patch/-/fast-json-patch-2.0.6.tgz#86fff8f8662391aa819722864d632e603e6ee605"
1030+
dependencies:
1031+
deep-equal "^1.0.1"
1032+
10161033
fast-levenshtein@~1.0.0:
10171034
version "1.0.7"
10181035
resolved "https://registry.yarnpkg.com/fast-levenshtein/-/fast-levenshtein-1.0.7.tgz#0178dcdee023b92905193af0959e8a7639cfdcb9"
@@ -1220,6 +1237,10 @@ isarray@~1.0.0:
12201237
version "1.0.0"
12211238
resolved "https://registry.yarnpkg.com/isarray/-/isarray-1.0.0.tgz#bb935d48582cba168c06834957a54a3e07124f11"
12221239

1240+
jiff@^0.7.3:
1241+
version "0.7.3"
1242+
resolved "https://registry.yarnpkg.com/jiff/-/jiff-0.7.3.tgz#42db5d9140f1804399bb501747055a9434f40f46"
1243+
12231244
js-tokens@^3.0.0, js-tokens@^3.0.2:
12241245
version "3.0.2"
12251246
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-3.0.2.tgz#9866df395102130e38f7f996bceb65443209c25b"
@@ -1243,6 +1264,10 @@ json-patch-test-suite@^1.1.0:
12431264
version "1.1.0"
12441265
resolved "https://registry.yarnpkg.com/json-patch-test-suite/-/json-patch-test-suite-1.1.0.tgz#e12a7f067371ce6953b55fa8d6e2f64800916711"
12451266

1267+
json-patch@^0.7.0:
1268+
version "0.7.0"
1269+
resolved "https://registry.yarnpkg.com/json-patch/-/json-patch-0.7.0.tgz#2598958ea67fa3660dae8ee684d35407b37f4b98"
1270+
12461271
json-stable-stringify@~0.0.0:
12471272
version "0.0.1"
12481273
resolved "https://registry.yarnpkg.com/json-stable-stringify/-/json-stable-stringify-0.0.1.tgz#611c23e814db375527df851193db59dd2af27f45"
@@ -1269,6 +1294,10 @@ jsonparse@^1.2.0:
12691294
version "1.3.1"
12701295
resolved "https://registry.yarnpkg.com/jsonparse/-/jsonparse-1.3.1.tgz#3f4dae4a91fac315f71062f8521cc239f1366280"
12711296

1297+
jsonpatch@^3.0.1:
1298+
version "3.0.1"
1299+
resolved "https://registry.yarnpkg.com/jsonpatch/-/jsonpatch-3.0.1.tgz#97225367c1c3c5bf1641be59b2f73be19759f06f"
1300+
12721301
jsonpointer@^4.0.0:
12731302
version "4.0.1"
12741303
resolved "https://registry.yarnpkg.com/jsonpointer/-/jsonpointer-4.0.1.tgz#4fd92cb34e0e9db3c89c8622ecf51f9b978c6cb9"
@@ -1490,6 +1519,10 @@ pbkdf2@^3.0.3:
14901519
safe-buffer "^5.0.1"
14911520
sha.js "^2.4.8"
14921521

1522+
platform@^1.3.3:
1523+
version "1.3.5"
1524+
resolved "https://registry.yarnpkg.com/platform/-/platform-1.3.5.tgz#fb6958c696e07e2918d2eeda0f0bc9448d733444"
1525+
14931526
prelude-ls@~1.1.0, prelude-ls@~1.1.1, prelude-ls@~1.1.2:
14941527
version "1.1.2"
14951528
resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.1.2.tgz#21932a549f5e52ffd9a827f570e04be62a97da54"

0 commit comments

Comments
 (0)