Example - selector caching

JavaScript performance comparison

Test case created by Cezar "ikari" Pokorski


This is an example test to show JSPerf capabilities and also to show why caching jQuery selector results outside of a loop is much faster. And how much.

Preparation code

<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script src="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
Benchmark.prototype.setup = function() {
    var $p = $('p');

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
Lookup every time
Cached lookup

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

Compare results of other browsers

1 comment

Cezar commented :

The newer Firefox, the slower...

Comment form temporarily disabled.

Add a comment