querySelectorAll vs getElementById

JavaScript performance comparison

Revision 45 of this test case created by zibi

Preparation code

<span data-l10n-id="foo0">gix</span>
<span data-l10n-id="foo1">gix</span>
<span data-l10n-id="foo2">gix</span>
<span data-l10n-id="foo3">gix</span>
<span data-l10n-id="foo4">gix</span>
<span data-l10n-id="foo5">gix</span>
<span data-l10n-id="foo6">gix</span>
<span data-l10n-id="foo7">gix</span>
<span data-l10n-id="foo8">gix</span>
<span data-l10n-id="foo9">gix</span>
<p id="foo">bar</p>
    

Preparation code output

<span data-l10n-id="foo0">gix</span> <span data-l10n-id="foo1">gix</span> <span data-l10n-id="foo2">gix</span> <span data-l10n-id="foo3">gix</span> <span data-l10n-id="foo4">gix</span> <span data-l10n-id="foo5">gix</span> <span data-l10n-id="foo6">gix</span> <span data-l10n-id="foo7">gix</span> <span data-l10n-id="foo8">gix</span> <span data-l10n-id="foo9">gix</span> <p id="foo">bar</p>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
querySelectorAll
var nodes = document.querySelectorAll('[data-l10n-id]');
for (var i = 0; i < nodes.length; i++) {
  var node = nodes[i];
}
pending…
querySelector
for (var i = 0; i < 10; i++) {
  var node = document.querySelector('[data-l10n-id=foo'+i+']');
}
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.

0 Comments

gix gix gix gix gix gix gix gix gix gix

bar