var in if

JavaScript performance comparison

Test case created by Patrick Engström

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<iframe src="javascript:0"></iframe>
<script>
Benchmark.prototype.setup = function() {
    function ihash(){ return $($('iframe')[0]).text() }
};
</script>

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
Var
var i = ihash();
if (i == 'bla' && i != 0)
  $($('iframe')[0]).text('hello');
pending…
No var
if (ihash() == 'bla' && ihash() != 0)
  $($('iframe')[0]).text('hello');
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