getElementById vs. querySelector (v62)

Revision 62 of this benchmark created on


Description

Compare the speed of getElementById to querySelector

Preparation HTML

<p id="foo">Foo</p>
<p id="bar">Bar</p>
<p id="baz">Baz</p>

Setup

var param = '#foo';
    var res;

Test runner

Ready to run.

Testing in
TestOps/sec
1 if
if (param[0] == '#') {
  res = document.getElementById(param);
}
ready
3 if
if (param.indexOf('#') == 0) {
  res = document.getElementById(param);
}
ready

Revisions

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