Skip to content

Instantly share code, notes, and snippets.

@markogresak
Last active August 29, 2015 14:27
Show Gist options
  • Save markogresak/9527d317e308ce633baa to your computer and use it in GitHub Desktop.
Save markogresak/9527d317e308ce633baa to your computer and use it in GitHub Desktop.
Comparison of delete vs Reflect.deleteProperty
/**
* Benchmark process:
* - generate an array with 100.000 random elements (0 - 999.999)
* - in each sampler function, remove first element from array
* Removing first element might turn out with better performance
* compared to real world usage.
*
*
* Tested in io.js v3.0.0, babel-node v5.8.21
* before using, run: npm install benchmark harmony-reflect
*/
'use strict';
var Benchmark = require('benchmark');
var Reflect = require('harmony-reflect');
var array = Array.apply(null, {length: 1e5}).map(function () {
return Math.floor(Math.random() * 1e6);
});
var arr = [];
new Benchmark.Suite()
.on('cycle start', function () {
arr = array.slice(0);
})
.add('delete [operator]', function () {
delete arr[0];
})
.add('Reflect#deleteProperty', function () {
Reflect.deleteProperty(arr, 0);
})
.add('Array#splice', function () {
arr.splice(0, 1);
})
.on('start', function () {
console.log('begin benchmark');
})
.on('cycle', function (event) {
console.log(String(event.target));
})
.run({async: true});

node (io.js) v3.0.0

delete [operator] x 10,035,966 ops/sec ±0.82% (98 runs sampled)
Reflect#deleteProperty x 5,588,987 ops/sec ±0.78% (93 runs sampled)
Array#splice x 9,494,060 ops/sec ±0.76% (91 runs sampled)

node v0.12.7

delete [operator] x 10,184,585 ops/sec ±0.84% (96 runs sampled)
Reflect#deleteProperty x 4,802,106 ops/sec ±0.66% (99 runs sampled)
Array#splice x 7,278,378 ops/sec ±0.77% (94 runs sampled)

babel-node v5.8.21

delete [operator] x 9,879,017 ops/sec ±0.95% (78 runs sampled)
Reflect#deleteProperty x 5,537,061 ops/sec ±0.82% (93 runs sampled)
Array#splice x 9,126,094 ops/sec ±0.61% (91 runs sampled)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment