Skip to content

Instantly share code, notes, and snippets.

@nickleefly
Last active March 24, 2016 09:40
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 nickleefly/952915fca4b8304ecba9 to your computer and use it in GitHub Desktop.
Save nickleefly/952915fca4b8304ecba9 to your computer and use it in GitHub Desktop.
isArray bench
$ node -v
v5.8.0
$ node bench.js

Start isArray

  2 tests completed.

  isArray  x 36,544,463 ops/sec ±4.89% (238 runs sampled)
  isArray1 x 43,869,363 ops/sec ±4.31% (247 runs sampled)

$ node -v
v5.9.1
$ node bench.js

Start isArray

  2 tests completed.

  isArray  x 41,617,178 ops/sec ±4.59% (243 runs sampled)
  isArray1 x 40,984,845 ops/sec ±4.85% (273 runs sampled)

while

$ node -v
v4.4.1
$ node bench.js

Start isArray

  2 tests completed.

  isArray  x 44,621,606 ops/sec ±6.41% (264 runs sampled)
  isArray1 x 47,319,872 ops/sec ±2.79% (284 runs sampled)

and

$ node -v
v4.4.0
$ node bench.js

Start isArray

  2 tests completed.

  isArray  x 47,998,121 ops/sec ±1.16% (280 runs sampled)
  isArray1 x 48,294,691 ops/sec ±0.92% (285 runs sampled)
var benchmark = require('benchmark')
var benchmarks = require('beautify-benchmark')
global.isArray = require('./index')
global.assert = require('assert')
var suite = new benchmark.Suite
var assertValues = 'assert.strictEqual(obj, true);'
suite.add({
name: 'isArray',
minSamples: 200,
fn: 'var obj = isArray.isArray([]);' + assertValues
})
suite.add({
name: 'isArray1',
minSamples: 200,
fn: 'var obj = isArray.isArray1([]);' + assertValues
})
suite.on('start', function onCycle(event) {
process.stdout.write('Start isArray' + '\n\n')
})
suite.on('cycle', function onCycle(event) {
benchmarks.add(event.target);
})
suite.on('complete', function onComplete() {
benchmarks.log();
})
suite.run({async: false})
var toString = {}.toString;
var isArray = Array.isArray || function (arr) {
return toString.call(arr) == '[object Array]';
};
var isArray1 = Array.isArray || function (arr) {
return Object.prototype.toString.call(arr) == '[object Array]';
};
module.exports = {
isArray: isArray,
isArray1: isArray1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment