Selector context
JavaScript performance comparison
Preparation code
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<div id="tree"></div>
<script>
Benchmark.prototype.setup = function() {
function CreateNDepthTree(N) {
if (N == 2) return $('<div/>', {
id: 'context'
}).append(CreateNDepthTree(N - 1));
else if (N == 1) return $('<div></div>', {
class: 'holder'
}).html('<h3>Leaf</h3>');
else return $('<div/>').append(CreateNDepthTree(N - 1));
}
var $context;
var dBody=document.body;
$(document).ready(function() {
$context = $("#context");
$('#tree').append(CreateNDepthTree(1000));
});
};
Benchmark.prototype.teardown = function() {
$('#tree').empty();
};
</script>
Preparation code output
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
$(".holder") |
|
pending… |
$(".holder", "#context") |
|
pending… |
$(".holder", $("#context")) |
|
pending… |
$(".holder", $context) |
|
pending… |
$context.find(".holder") |
|
pending… |
$context.filter('.holder') |
|
pending… |
$context.find('*').filter('.holder') |
|
pending… |
Compare results of other browsers
Revisions
You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:
- Revision 1: published
- Revision 2: published
- Revision 4: published
- Revision 5: published
- Revision 6: published by NPerfTestXXX
- Revision 7: published
- Revision 8: published by Andrei
- Revision 9: published
0 comments