Skip to content
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

Added jsondiffpatch.clone() to benchmarks #34

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
644 changes: 644 additions & 0 deletions benchmark/fixture2.json

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions benchmark/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const fastCopy = require('fast-copy').default
const obj = require('./fixture.json')
const clone = require('..')
const copyFastestJsonCopy = require('fastest-json-copy').copy
const jsondiffpatchClone = require('jsondiffpatch').clone
const plainObjectClone = require('plain-object-clone')
const nanoCopy = require('nano-copy')
const ramdaClone = require('ramda').clone
Expand Down Expand Up @@ -47,6 +48,12 @@ var run = bench([
}
setImmediate(cb)
},
function benchJsondiffpatchClone (cb) {
for (var i = 0; i < max; i++) {
jsondiffpatchClone(obj)
}
setImmediate(cb)
},
function benchPlainObjectClone (cb) {
for (var i = 0; i < max; i++) {
plainObjectClone(obj)
Expand Down
7 changes: 7 additions & 0 deletions benchmark/shallow.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const fastCopy = require('fast-copy').default
const obj = {a: 'a', b: 'b', c: 'c'}
const clone = require('..')
const copyFastestJsonCopy = require('fastest-json-copy').copy
const jsondiffpatchClone = require('jsondiffpatch').clone
const plainObjectClone = require('plain-object-clone')
const nanoCopy = require('nano-copy')
const ramdaClone = require('ramda').clone
Expand Down Expand Up @@ -47,6 +48,12 @@ var run = bench([
}
setImmediate(cb)
},
function benchJsondiffpatchClone (cb) {
for (var i = 0; i < max; i++) {
jsondiffpatchClone(obj)
}
setImmediate(cb)
},
function benchPlainObjectClone (cb) {
for (var i = 0; i < max; i++) {
plainObjectClone(obj)
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"fast-copy": "^1.2.1",
"fastbench": "^1.0.1",
"fastest-json-copy": "^1.0.1",
"jsondiffpatch": "^0.4.1",
"lodash.clonedeep": "^4.5.0",
"nano-copy": "^0.1.0",
"plain-object-clone": "^1.1.0",
Expand Down
33 changes: 19 additions & 14 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,22 +103,27 @@ npm run bench
```

```
benchDeepCopy*100: 671.675ms
benchLodashCloneDeep*100: 1.574s
benchCloneDeep*100: 936.792ms
benchFastCopy*100: 822.668ms
benchFastestJsonCopy*100: 363.898ms // See note below
benchPlainObjectClone*100: 556.635ms
benchNanoCopy*100: 770.234ms
benchRamdaClone*100: 2.695s
benchJsonParseJsonStringify*100: 2.290s // JSON.parse(JSON.stringify(obj))
benchRfdc*100: 412.818ms
benchRfdcProto*100: 424.076ms
benchRfdcCircles*100: 443.357ms
benchRfdcCirclesProto*100: 465.053ms
benchDeepCopy*100: 550.406ms
benchLodashCloneDeep*100: 1.479s
benchCloneDeep*100: 761.46ms
benchFastCopy*100: 800.38ms
benchFastestJsonCopy*100: 369.979ms // See note below
benchJsondiffpatchClone*100: 285.914ms // See note below
benchPlainObjectClone*100: 544ms
benchNanoCopy*100: 640.636ms
benchRamdaClone*100: 2.936s
benchJsonParseJsonStringify*100: 2.239s // JSON.parse(JSON.stringify(obj))
benchRfdc*100: 403.151ms
benchRfdcProto*100: 416.896ms
benchRfdcCircles*100: 453.706ms
benchRfdcCirclesProto*100: 404.127ms
```

It is true that [fastest-json-copy](https://www.npmjs.com/package/fastest-json-copy) may be faster, BUT it has such huge limitations that it is rarely useful. For example, it treats things like `Date` and `Map` instances the same as empty `{}`. It can't handle circular references. [plain-object-clone](https://www.npmjs.com/package/plain-object-clone) is also really limited in capability.
It is true that `jsondiffpatch.clone()` from [jsondiffpatch](https://www.npmjs.com/package/jsondiffpatch) is the fastest in that benchmark run, but it cannot handle as many situations as `rfdc` can. Also, [this](https://www.measurethat.net/Benchmarks/ShowResult/202870) and [this benchmark result](https://www.measurethat.net/Benchmarks/ShowResult/202871) suggest that `rfdc` is faster in Firefox and Chrome at [this different benchmark](https://www.measurethat.net/Benchmarks/Show/13538/3/lodash-clonedeep-vs-jsonparsejsonstringify-vs-fastest-j).

It is true that [fastest-json-copy](https://www.npmjs.com/package/fastest-json-copy) is faster than `rfdc` in this particular benchmark, but we have seen that, [with different input](benchmark/fixture2.json), the opposite is true. Also, fastest-json-copy has such huge limitations that it is rarely useful. For example, it treats things like `Date` and `Map` instances the same as empty `{}`. It can't handle circular references.

[plain-object-clone](https://www.npmjs.com/package/plain-object-clone) is also really limited in capability.

## Tests

Expand Down