swith / if

JavaScript performance comparison

Revision 2 of this test case created

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
switch
var type = 'angle',
    value = 90;

switch (type) {
case 'damage':
  return -value;
case 'angle':
  return value / 180 * Math.PI;
}
pending…
if
var type = 'angle',
    value = 90;

if (type === 'damage') {
  return -damage;
} else if (type === 'angle') {
  return value / 180 * Math.PI;
}
pending…
?:
var type = 'angle',
    value = 90;

return type === 'damage' ? -damage : (type === 'angle' ? value / 180 * Math.PI : undefined);
pending…
?: - 2
var type = 'angle',
    value = 90;

return type === 'damage' ? -damage : type === 'angle' && value / 180 * Math.PI;
pending…
if - 2
var type = 'angle',
    value = 90;

if (type == 'damage') {
  return -damage;
} else if (type == 'angle') {
  return value / 180 * Math.PI;
}
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment