binary vs if condition

Benchmark created by sandeep on


Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<a href="javascript:void(0)" id="ancId" onclick="javascript:condTest(this.id)">Click Me</a>
<div id="test">
</div>
<script>
  $(document).ready(function() {
    $("#ancId").click();
  });
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
if condition
function condTest(eleId) {
  if (eleId) {
    $("#test").append("<div height='25px'>hi i m </div>");
  } else {
    $("#test").append("<div height='25px'>hi i m 2 </div>");
  }
}
ready
binary condition
function condTest(eleId) {
  function condTest(a) {
    a ? $("#test").append("<div height='25px'>hi i m </div>") : $("#test").append("<div height='25px'>hi i m 2 </div>")
  };
};
ready

Revisions

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

  • Revision 1: published by sandeep on