map vs push

Benchmark created on


Test runner

Ready to run.

Testing in
TestOps/sec
map
var a = [{x:"1", y:true},{x:"2",y:false},
{x:"1", y:true},{x:"2",y:false},
{x:"1", y:true},{x:"2",y:false},
{x:"1", y:true},{x:"2",y:false},
{x:"1", y:true},{x:"2",y:false},
{x:"1", y:true},{x:"2",y:false},
{x:"1", y:true},{x:"2",y:false},
{x:"1", y:true},{x:"2",y:false},
{x:"1", y:true},{x:"2",y:false},
{x:"1", y:true},{x:"2",y:false},
{x:"1", y:true},{x:"2",y:false},
{x:"1", y:true},{x:"2",y:false},
{x:"1", y:true},{x:"2",y:false},
{x:"1", y:true},{x:"2",y:false},
{x:"1", y:true},{x:"2",y:false},
{x:"1", y:true},{x:"2",y:false},
{x:"1", y:true},{x:"2",y:false},
{x:"1", y:true},{x:"2",y:false},
{x:"1", y:true},{x:"2",y:false},
{x:"1", y:true},{x:"2",y:false}
];
a.map(function(item){return item.y ? item.x : '';}).join('').split('');
ready
no map
var a = [{x:"1", y:true},{x:"2",y:false},
{x:"1", y:true},{x:"2",y:false},
{x:"1", y:true},{x:"2",y:false},
{x:"1", y:true},{x:"2",y:false},
{x:"1", y:true},{x:"2",y:false},
{x:"1", y:true},{x:"2",y:false},
{x:"1", y:true},{x:"2",y:false},
{x:"1", y:true},{x:"2",y:false},
{x:"1", y:true},{x:"2",y:false},
{x:"1", y:true},{x:"2",y:false},
{x:"1", y:true},{x:"2",y:false},
{x:"1", y:true},{x:"2",y:false},
{x:"1", y:true},{x:"2",y:false},
{x:"1", y:true},{x:"2",y:false},
{x:"1", y:true},{x:"2",y:false},
{x:"1", y:true},{x:"2",y:false},
{x:"1", y:true},{x:"2",y:false},
{x:"1", y:true},{x:"2",y:false},
{x:"1", y:true},{x:"2",y:false},
{x:"1", y:true},{x:"2",y:false}
];

var out = [];

for(var i = 0; i < a.length; i++)
{
   var item = a[i];
   if(item.y)
   {
      out.push(item.x);
   }
}
ready

Revisions

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