Skip to content

Instantly share code, notes, and snippets.

@jnv
Last active March 23, 2017 13:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jnv/33107e497d610ae9ac79f227262e7b68 to your computer and use it in GitHub Desktop.
Save jnv/33107e497d610ae9ac79f227262e7b68 to your computer and use it in GitHub Desktop.
# Logs
logs
*.log
npm-debug.log*
# Runtime data
pids
*.pid
*.seed
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
# nyc test coverage
.nyc_output
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# node-waf configuration
.lock-wscript
# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules
jspm_packages
# Optional npm cache directory
.npm
# Optional REPL history
.node_repl_history
'use strict'
const Benchmark = require('benchmark')
const suite = new Benchmark.Suite
global._ = require('lodash')
const params = {
setup: () => {
const data = []
for (let i = 100; i >= 0; i--) {
const obj = {}
obj[i] = 'a'
obj[i*1000] = 'b'
obj[i*10000] = 'c'
obj[i*100000] = 'd'
data.push(obj)
}
},
strict: true,
}
suite
.add('Native assign + apply', function() {
Object.assign.apply(Object, data)
}, params)
.add('Native expand assign', function() {
Object.assign(...data)
}, params)
.add('LoDash reduce assign', function() {
_.reduce(data, _.extend)
}, params)
.add('LoDash expand assign', function() {
_.assign({}, ...data)
}, params)
.on('cycle', function(event) {
console.log(String(event.target));
})
.on('complete', function() {
console.log('Fastest is ' + this.filter('fastest').map('name'));
})
// run async
.run({async: true})
{
"name": "benchmarks",
"version": "0.0.0",
"main": "index.js",
"author": "Jan Vlnas",
"license": "MIT",
"dependencies": {
"benchmark": "^2.1.3",
"lodash": "^4.17.4",
"microtime": "^2.1.2"
}
}
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
benchmark@^2.1.3:
version "2.1.3"
resolved "https://registry.yarnpkg.com/benchmark/-/benchmark-2.1.3.tgz#e10e40e4d53d0e1c9d77a834fde593994dca7f0c"
dependencies:
lodash "^4.17.3"
platform "^1.3.3"
bindings@1.2.x:
version "1.2.1"
resolved "https://registry.yarnpkg.com/bindings/-/bindings-1.2.1.tgz#14ad6113812d2d37d72e67b4cacb4bb726505f11"
lodash@^4.17.3, lodash@^4.17.4:
version "4.17.4"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae"
microtime@^2.1.2:
version "2.1.2"
resolved "https://registry.yarnpkg.com/microtime/-/microtime-2.1.2.tgz#9c955d0781961ab13a1b6f9a82b080f5d7ecd83b"
dependencies:
bindings "1.2.x"
nan "2.4.x"
nan@2.4.x:
version "2.4.0"
resolved "https://registry.yarnpkg.com/nan/-/nan-2.4.0.tgz#fb3c59d45fe4effe215f0b890f8adf6eb32d2232"
platform@^1.3.3:
version "1.3.3"
resolved "https://registry.yarnpkg.com/platform/-/platform-1.3.3.tgz#646c77011899870b6a0903e75e997e8e51da7461"
@jnv
Copy link
Author

jnv commented Mar 23, 2017

Native assign + apply x 8,811 ops/sec ±1.16% (90 runs sampled)
Native expand assign x 7,830 ops/sec ±1.05% (93 runs sampled)
LoDash reduce assign x 6,179 ops/sec ±1.40% (86 runs sampled)
LoDash expand assign x 5,599 ops/sec ±0.73% (94 runs sampled)
Fastest is Native assign + apply

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment