third switch vs if

Benchmark created by hrkei on


Test runner

Ready to run.

Testing in
TestOps/sec
third switch
var result = 0;
for(var i=0; i<3; i++) {
switch(i) {
case 0:
result = i;
break;
case 1:
result = i+1;
break;
case 2:
result = i+2;
break;
}
}
ready
third if
var result = 0;
for(var i=0; i<3; i++) {
if(i==0) {
result = i;
} else if(i==1) {
result = i+1;
} else if(i==2) {
result = i+2;
}
}
ready

Revisions

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

  • Revision 1: published by hrkei on