Duplicate array of objects test

JavaScript performance comparison

Test case created by Vanja Gavric

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var a = {single: 'property'};
  var b = {single: 'property'}; // create an identical object manually
  var c = a; // copy by reference
  
  var d = {
  	some: {
  		super: {
  			duper: {
  				very: {
  					much: {
  						deeply: {
  							nested: 'property',
  						},
  					},
  				},
  			},
  		}
  	},
  };
  var e = Object.assign({}, d); // deep copy object
  var f = d; // copy by reference
  
  var g = {
  	arr: ['a', 'b', 'c'],
  };
  var h = Object.assign({}, g);
  var i = g;
  
  var arr = [a, d, e, f, g, h, i, b, c];

};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
indexOf output array
var result = [];
arr.forEach(function(item, i) {
    if (result.indexOf(item) === -1) {
        result.push(item);
    }
});
return result;
pending…
filter (indexOf entire input arr)
return arr.filter(function(item, i, originalArray) {
	return originalArray.indexOf(item) === i;
});
pending…
spread Set
return [...new Set(arr)];
pending…

You can edit these tests or add even more tests to this page by appending /edit to the URL.

0 Comments