if vs 2for

Benchmark created by ashnur on


Setup

var inp = Array.apply(null, Array(100)).map(function(){
    return Math.floor(Math.random()*100)
    })
    var out = []

Teardown


    out = []
  

Test runner

Ready to run.

Testing in
TestOps/sec
if
for ( var i = 0; i < 100; i++ ) {
  if ( i < 50 ) {
    out.push(inp[i] * Math.random())
  } else {
    out.push(inp[i] * 2)
  }
}
ready
2for
for ( var i = 0; i < 50; i++ ) {
    out.push(inp[i] * Math.random())
}
for ( ; i < 100; i++ ) {
    out.push(inp[i] * 2)
}
ready

Revisions

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