getElementsByTagname("a")[0] vs. querySelector("a")
JavaScript performance comparison
Preparation code
<script src="https://code.jquery.com/jquery-git2.min.js"></script>
<input type="password"></input><input type="password"></input>
<input type="password"></input><input type="password"></input>
<script>
Benchmark.prototype.setup = function() {
var list, result, i, len;
var hasFields = false;
};
Benchmark.prototype.teardown = function() {
hasFields = false;
};
</script>
Preparation code output
<input type="password"></input><input type="password"></input>
<input type="password"></input><input type="password"></input>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
Test | Ops/sec | |
---|---|---|
Using getElementsByTagName()
|
|
pending… |
Using querySelectorAll()
|
|
pending… |
Using querySelector()
|
|
pending… |
jQuery
|
|
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.
- Revision 1: published Nicholas C. Zakas
- Revision 4: published Scott Sauyet
- Revision 7: published Jorge Chamorro
- Revision 9: published Jorge Chamorro
- Revision 11: published vamp
- Revision 12: published
- Revision 13: published
- Revision 14: published bar
- Revision 15: published Dan
- Revision 16: published
- Revision 17: published
- Revision 18: published
- Revision 19: published
- Revision 20: published
- Revision 21: published and last updated
- Revision 22: published
- Revision 25: published
0 Comments