repositories
/
benchmarks-js.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Update volta pnpm version
[benchmarks-js.git]
/
shallow-clone-object.js
diff --git
a/shallow-clone-object.js
b/shallow-clone-object.js
index 131b5e974842c7217657ebd409cd9f6d618a31ef..f8e193b65e701a7d91294cfa6bf973cd7d6b696d 100644
(file)
--- a/
shallow-clone-object.js
+++ b/
shallow-clone-object.js
@@
-1,23
+1,19
@@
/* eslint-disable no-unused-vars */
const Benchmark = require('benny')
/* eslint-disable no-unused-vars */
const Benchmark = require('benny')
-const { generateRandomInteger } = require('./benchmark-utils')
const _ = require('lodash')
const _ = require('lodash')
+const { generateRandomObject } = require('./benchmark-utils')
-const size = generateRandomInteger(500)
-const testObject = {}
-for (let i = 0; i < size; i++) {
- testObject[i.toString()] = i
-}
+const object = generateRandomObject()
Benchmark.suite(
Benchmark.suite(
- `Shallow clone object with ${
size
} keys`,
- Benchmark.add('Spread', (obj =
testO
bject) => {
+ `Shallow clone object with ${
Object.keys(object).length
} keys`,
+ Benchmark.add('Spread', (obj =
o
bject) => {
const objClone = { ...obj }
}),
const objClone = { ...obj }
}),
- Benchmark.add('Object assign', (obj =
testO
bject) => {
+ Benchmark.add('Object assign', (obj =
o
bject) => {
const objClone = Object.assign({}, obj)
}),
const objClone = Object.assign({}, obj)
}),
- Benchmark.add('lodash clone', (obj =
testO
bject) => {
+ Benchmark.add('lodash clone', (obj =
o
bject) => {
const objClone = _.clone(obj)
}),
Benchmark.cycle(),
const objClone = _.clone(obj)
}),
Benchmark.cycle(),
@@
-37,4
+33,6
@@
Benchmark.suite(
format: 'table.html',
details: true
})
format: 'table.html',
details: true
})
-)
+).catch(err => {
+ console.error(err)
+})