precreate jquery objects

JavaScript performance comparison

Test case created by Göran Andersson

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<div id="d1">
</div>
<div id="d2">
</div>
<div id="d3">
</div>
<div id="d4">
</div>
<div id="d5">
</div>
<script>
Benchmark.prototype.setup = function() {
    var ids = ['d1', 'd2', 'd3', 'd4', 'd5'];
    var objs = [$('#d1'), $('#d2'), $('#d3'), $('#d4'), $('#d5')];
};
</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
create
$.each(ids, function(k, v) {
  $('#' + v).hide();
});
pending…
precreate
$.each(objs, function(k, v) {
  v.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