X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=deep-clone-object.mjs;h=00753e2f439ed0df4c3d7c0250cdf4f687cd2606;hb=89c19618ba2802c2cb6fac6d5b4bb786ad96f1e5;hp=be98817da7967080ecec8d95b60e1a8edb3be266;hpb=95d31631e49a5a39e261745c31f526691dab5f81;p=benchmarks-js.git diff --git a/deep-clone-object.mjs b/deep-clone-object.mjs index be98817..00753e2 100644 --- a/deep-clone-object.mjs +++ b/deep-clone-object.mjs @@ -1,46 +1,35 @@ /* eslint-disable no-unused-vars */ -import Benchmark from 'benny' -import _ from 'lodash' -import clone from 'just-clone' import deepClone from 'deep-clone' +import clone from 'just-clone' +import _ from 'lodash' +import { clone as rambdaClone } from 'rambda' +import { bench, group, run } from 'tatami-ng' + import { generateRandomObject } from './benchmark-utils.mjs' const object = generateRandomObject() -Benchmark.suite( - `Deep clone object with ${Object.keys(object).length} keys`, - Benchmark.add('JSON stringify/parse', (obj = object) => { - const objClone = JSON.parse(JSON.stringify(obj)) - }), - Benchmark.add('structuredClone', (obj = object) => { - const objClone = structuredClone(obj) - }), - Benchmark.add('lodash cloneDeep', (obj = object) => { - const objClone = _.cloneDeep(obj) - }), - Benchmark.add('just-clone', (obj = object) => { - const objClone = clone(obj) - }), - Benchmark.add('deep-clone', (obj = object) => { - const objClone = deepClone(obj) - }), - Benchmark.cycle(), - Benchmark.complete(), - Benchmark.save({ - file: 'deep-clone-object', - format: 'json', - details: true - }), - Benchmark.save({ - file: 'deep-clone-object', - format: 'chart.html', - details: true - }), - Benchmark.save({ - file: 'deep-clone-object', - format: 'table.html', - details: true +group(`Deep clone object with ${Object.keys(object).length} keys`, () => { + bench('JSON stringify/parse', (obj = object) => { + const objCloned = JSON.parse(JSON.stringify(obj)) + }) + bench('structuredClone', (obj = object) => { + const objCloned = structuredClone(obj) }) -).catch(err => { - console.error(err) + bench('lodash cloneDeep', (obj = object) => { + const objCloned = _.cloneDeep(obj) + }) + bench('rambda clone', (obj = object) => { + const objCloned = rambdaClone(obj) + }) + bench('just-clone', (obj = object) => { + const objCloned = clone(obj) + }) + bench('deep-clone', (obj = object) => { + const objCloned = deepClone(obj) + }) +}) + +await run({ + units: true })