ES6 Set vs Array properties

JavaScript performance comparison

Revision 173 of this test case created by Eric

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var key = "";
  
  var set = new Set();
  var arr = [];
  
  var set2 = new Set();
  var arr2 = [];
  
  function randomString() {
    var text = "";
    var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
  
    for (var i = 0; i < 5; i++) {
      text += possible.charAt(Math.floor(Math.random() * possible.length));
    }
  
    return text;
  }
  
  for (var i = 0; i < 1000; i++) {
    var key = randomString();
    set2.add(key);
    arr2.push(key);
  }

};

Benchmark.prototype.teardown = function() {
  key = randomString();

};
</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
Iterate Array for of
for (var key of arr2) {
  if (arr2.hasOwnProperty(key)) {
    var val = arr2[key];
  }
}
pending…

Revisions

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

0 Comments