Skip to content

Instantly share code, notes, and snippets.

@lpinca
Last active August 29, 2015 14:26
Show Gist options
  • Save lpinca/b75c5fa4321a89e9eed2 to your computer and use it in GitHub Desktop.
Save lpinca/b75c5fa4321a89e9eed2 to your computer and use it in GitHub Desktop.
Test case for redis/ioredis#120
'use strict';
var Benchmark = require('benchmark')
, _ = require('lodash');
var suite = new Benchmark.Suite()
, arr = []
, i;
for (i = 0; i < 1000; i++) arr.push(i);
suite.add('without copy loop', function () {
var args = new Array(1);
args[0] = arr;
_.flatten(args);
})
.add('with copy loop', function () {
var args = new Array(arr.length)
, i;
for (i = 0; i < arr.length; i++) args[i] = arr[i];
_.flatten(args);
})
.on('cycle', function (event) {
console.log(String(event.target));
})
.on('complete', function() {
console.log('Fastest is ' + this.filter('fastest').pluck('name'));
})
.run({ 'async': true });
{
"name": "ioredis-120",
"version": "1.0.0",
"description": "",
"main": "index.js",
"dependencies": {
"benchmark": "^1.0.0",
"lodash": "^3.10.0"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment