ES6 Set vs Array properties

JavaScript performance comparison

Revision 174 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
array push
for (var i=0; i < 1000; i++) {
   arr.push(key);
}
pending…
set add
for (var i=0; i < 1000; i++) {
   set.add(key);
}
pending…

Revisions

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

0 Comments