This repository was archived by the owner on Mar 6, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbenchmark.js
More file actions
47 lines (42 loc) · 1.29 KB
/
benchmark.js
File metadata and controls
47 lines (42 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
'use strict'
/* eslint-disable no-console */
var benchmark = require('benchmark')
var ooPatch = require('./index')
var jsonpatch = require('jsonpatch') // https://github.com/dharmafly/jsonpatch.js
var json_patch = require('json-patch') // https://github.com/bruth/jsonpatch-js
var jiff = require('jiff') // https://github.com/cujojs/jiff
var fastjsonpatch = require('fast-json-patch') // https://github.com/Starcounter-Jack/JSON-Patch
var doc = {
"foo": [1, 2, 3, 4],
"baz": [{
"qux": "hello",
}],
}
var patch = [{
"op": "replace",
"path": "/baz/0/qux",
"value": "world",
}]
benchmark.Suite('apply patch') // eslint-disable-line
.add('github: json8/patch - npm: json8-patch', function() {
ooPatch.apply(doc, patch)
})
.add('github: dharmafly/jsonpatch.js / npm: jsonpatch', function() {
jsonpatch.apply_patch(doc, patch)
})
.add('github: bruth/jsonpatch-js / npm: json_patch', function() {
json_patch.apply(doc, patch)
})
.add('github: cujojs/jiff / npm: jiff', function() {
jiff.patch(patch, doc)
})
.add('github: Starcounter-Jack/JSON-Patch / npm: fast-json-patch', function() {
fastjsonpatch.apply(doc, patch)
})
.on('cycle', function(event) {
console.log(event.target.toString())
})
.on('complete', function() {
console.log('Fastest is ' + this.filter('fastest').map('name'))
})
.run()