Skip to content

Instantly share code, notes, and snippets.

@Tom910
Tom910 / Object-keys-vs-for-in.js
Last active January 24, 2017 10:12
Object-keys-vs-for-in
var Benchmark = require('benchmark');
var suite = new Benchmark.Suite;
var testObject = {};
for (var s = 0; s < 1000; s++) {
testObject[s] = Math.floor(Math.random() * 10000);
}
console.log('Testing iteration of object')
@Tom910
Tom910 / gist:37d3c863103c87741d835738af03b3ba
Created January 13, 2017 08:04
for-cache-vs-no-cache
var Benchmark = require('benchmark');
var suite = new Benchmark.Suite;
var testArray = [];
for (var s = 0; s < 1000; s++) {
testArray.push(s * 2);
}
suite
var Benchmark = require('benchmark');
var expect = require('expect');
var _ = require('lodash');
var R = require('ramda');
var suite = new Benchmark.Suite;
var testArray = [
{ items: [{status: 'new', payload: [1, 2, 3]}, {status: 'old'}, {status: 'new', payload: [2, 1, 4]}]},
{ items: [{status: 'new', payload: [8, 2, 7]}, {status: 'new', payload: [0, 2, 9]}, {status: 'old'}]},
{ items: [{status: 'old'}, {status: 'new', payload: [5, 2, 3]}, {status: 'new', payload: [1, 4, 3]}]}
var Benchmark = require('benchmark');
var expect = require('expect');
var _ = require('lodash');
var R = require('ramda');
var suite = new Benchmark.Suite;
var testArray = [1,2,3,4,5,6,7,8,9,10,11,12,13];
var resultat = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26];
suite
var Benchmark = require('benchmark');
var expect = require('expect');
var suite = new Benchmark.Suite;
var testArray = [1,2,3,4,5,6,7,8,9,10,11,12,13];
var resultat = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26];
suite
.add('forHoley', () => forHoley(testArray))
.add('forPush', () => forPush(testArray))