OR vs if (v12)

Revision 12 of this benchmark created by Andrew on


Setup

var flag = true
      , i = 1
      , string = 'qwerty'
      , obj = {}
      , zero = 0
      , emptyString = ''
      ;

Test runner

Ready to run.

Testing in
TestOps/sec
OR_i
var result = flag || i;
ready
OR_string
var result = flag || string;
ready
OR_obj
var result = flag || obj;
ready
OR_zero
var result = flag || zero;
ready
OR_emptyString
var result = flag || emptyString;
ready
IF_i
if ( flag ) {
 var result = flag;
} else {
 var result = i;
}
ready
IF_string
if ( flag ) {
 var result = flag;
} else {
 var result = string;
}
ready
IF_obj
if ( flag ) {
 var result = flag;
} else {
 var result = obj;
}
ready
IF_zero
if ( flag ) {
 var result = flag;
} else {
 var result = zero;
}
ready
IF_emptyString
if ( flag ) {
 var result = flag;
} else {
 var result = emptyString;
}
ready

Revisions

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