mutli function vs if

JavaScript performance comparison

Test case created

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<div class="one"></div>
<div class="two"></div>

Preparation code output

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
multiple functions
$('.one').click(function(){
$(this).hide();
});
$('.two').click(function(){
$(this).hide();
});
pending…
if
if ($('div').hasClass('one')) {
$(this).hide();
} else if ($('div').hasClass('two')) {
$(this).hide();
}
pending…

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

Compare results of other browsers

0 comments

Add a comment