X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=deep-clone-object.mjs;h=eda04d0d83e47d52ae7d6340dc8940bbf69bb5c9;hb=838fbe3a0be9d00f09a427d20afc7e8303fc20ba;hp=9ed4037324d5507c23f5443021385998346e9d74;hpb=48f5216deed3bc4d9a64e81822fe8d6bd5c5cdcd;p=benchmarks-js.git diff --git a/deep-clone-object.mjs b/deep-clone-object.mjs index 9ed4037..eda04d0 100644 --- a/deep-clone-object.mjs +++ b/deep-clone-object.mjs @@ -1,46 +1,34 @@ -/* 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 objCloned = JSON.parse(JSON.stringify(obj)) - }), - Benchmark.add('structuredClone', (obj = object) => { - const objCloned = structuredClone(obj) - }), - Benchmark.add('lodash cloneDeep', (obj = object) => { - const objCloned = _.cloneDeep(obj) - }), - Benchmark.add('just-clone', (obj = object) => { - const objCloned = clone(obj) - }), - Benchmark.add('deep-clone', (obj = object) => { - const objCloned = 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) => { + JSON.parse(JSON.stringify(obj)) + }) + bench('structuredClone', (obj = object) => { + structuredClone(obj) }) -).catch((err) => { - console.error(err) + bench('lodash cloneDeep', (obj = object) => { + _.cloneDeep(obj) + }) + bench('rambda clone', (obj = object) => { + rambdaClone(obj) + }) + bench('just-clone', (obj = object) => { + clone(obj) + }) + bench('deep-clone', (obj = object) => { + deepClone(obj) + }) +}) + +await run({ + units: true, })