Underscore _.union x Array push (v2)

Revision 2 of this benchmark created by bali on


Description

Test if re assign variable with underscore union is faster than push values to variable.

Preparation HTML

<script src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.5.2/underscore-min.js"></script>

Setup

var x = [],
      y = [],
      i = 0;
    
    for (i; i < 100; i++) {
      x.push(_.random(0, 100));
      y.push(_.random(50, 150));
    }

Teardown


    console.log(x)
  

Test runner

Ready to run.

Testing in
TestOps/sec
Union re assign variable with underscore
x = _.union(x, y);
ready
Push variable to existing var
for (i = 0; i < 100; i++) {
  x.push(y[i]);
}
ready
Concat and re assign
x = x.concat(y);
ready

Revisions

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