ternary vs if

Benchmark created by timmywil on


Description

Compare performance of a ternary vs an if statement

Preparation HTML

<div id="test"></div>
<script>
  var elem = document.getElementById('test'),
      asg;
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
ternary
asg = elem.className === 'foo' ? elem : undefined;
ready
if statement
if (elem.className === 'foo') {
 asg = elem;
} else {
 asg = undefined;
}
ready

Revisions

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

  • Revision 1: published by timmywil on