doms ele

JavaScript performance comparison

Revision 4 of this test case created by Cezary Tomczyk

Preparation code

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<div id="content">
  <p>
    <a href="#" data-trans="asdfasdf" data-trans-tooltip="asdfasdf" title="aasdfas">asdf</a>
  </p>
  <p>
    <a href="#" data-trans="asdfasdf" data-trans-tooltip="asdfasdf" title="aasdfas">asdf</a>
  </p>
  <p>
    <a href="#" data-trans="asdfasdf" data-trans-tooltip="asdfasdf" title="aasdfas">asdf</a>
  </p>
  <p>
    <a href="#" data-trans="asdfasdf" data-trans-tooltip="asdfasdf" title="aasdfas">asdf</a>
  </p>
  <p>
    <a href="#" data-trans="asdfasdf" data-trans-tooltip="asdfasdf" title="aasdfas">asdf</a>
  </p>
  <p>
    <a href="#" data-trans="asdfasdf" data-trans-tooltip="asdfasdf" title="aasdfas">asdf</a>
  </p>
  <p>
    <a href="#" data-trans="asdfasdf" data-trans-tooltip="asdfasdf" title="aasdfas">asdf</a>
  </p>
  <p>
    <a href="#" data-trans="asdfasdf" data-trans-tooltip="asdfasdf" title="aasdfas">asdf</a>
  </p>
  <p>
    <a href="#" data-trans="asdfasdf" data-trans-tooltip="asdfasdf" title="aasdfas">asdf</a>
  </p>
  <p>
    <a href="#" data-trans="asdfasdf" data-trans-tooltip="asdfasdf" title="aasdfas">asdf</a>
  </p>
  <p>
    <a href="#" data-trans="asdfasdf" data-trans-tooltip="asdfasdf" title="aasdfas">asdf</a>
  </p>
  <p>
    <a href="#" data-trans="asdfasdf" data-trans-tooltip="asdfasdf" title="aasdfas">asdf</a>
  </p>
  <p>
    <a href="#" data-trans="asdfasdf" data-trans-tooltip="asdfasdf" title="aasdfas">asdf</a>
  </p>
  <p>
    <a href="#" data-trans="asdfasdf" data-trans-tooltip="asdfasdf" title="aasdfas">asdf</a>
  </p>
  <p>
    <a href="#" data-trans="asdfasdf" data-trans-tooltip="asdfasdf" title="aasdfas">asdf</a>
  </p>
  <p>
    <a href="#" data-trans="asdfasdf" data-trans-tooltip="asdfasdf" title="aasdfas">asdf</a>
  </p>
  <p>
    <a href="#" data-trans="asdfasdf" data-trans-tooltip="asdfasdf" title="aasdfas">asdf</a>
  </p>
  <p>
    <a href="#" data-trans="asdfasdf" data-trans-tooltip="asdfasdf" title="aasdfas">asdf</a>
  </p>
  <p>
    <a href="#" data-trans="asdfasdf" data-trans-tooltip="asdfasdf" title="aasdfas">asdf</a>
  </p>
  <p>
    <a href="#" data-trans="asdfasdf" data-trans-tooltip="asdfasdf" title="aasdfas">asdf</a>
  </p>
  <p>
    <a href="#" data-trans="asdfasdf" data-trans-tooltip="asdfasdf" title="aasdfas">asdf</a>
  </p>
  <p>
    <a href="#" data-trans="asdfasdf" data-trans-tooltip="asdfasdf" title="aasdfas">asdf</a>
  </p>
  <p>
    <a href="#" data-trans="asdfasdf" data-trans-tooltip="asdfasdf" title="aasdfas">asdf</a>
  </p>
  <p>
    <a href="#" data-trans="asdfasdf" data-trans-tooltip="asdfasdf" title="aasdfas">asdf</a>
  </p>
  <p>
    <a href="#" data-trans="asdfasdf" data-trans-tooltip="asdfasdf" title="aasdfas">asdf</a>
  </p>
  <p>
    <a href="#" data-trans="asdfasdf" data-trans-tooltip="asdfasdf" title="aasdfas">asdf</a>
  </p>
  <p>
    <a href="#" data-trans="asdfasdf" data-trans-tooltip="asdfasdf" title="aasdfas">asdf</a>
  </p>
  <p>
    <a href="#" data-trans="asdfasdf" data-trans-tooltip="asdfasdf" title="aasdfas">asdf</a>
  </p>
  <p>
    <a href="#" data-trans="asdfasdf" data-trans-tooltip="asdfasdf" title="aasdfas">asdf</a>
  </p>
  <p>
    <a href="#" data-trans="asdfasdf" data-trans-tooltip="asdfasdf" title="aasdfas">asdf</a>
  </p>
  <p>
    <a href="#" data-trans="asdfasdf" data-trans-tooltip="asdfasdf" title="aasdfas">asdf</a>
  </p>
  <p>
    <a href="#" data-trans="asdfasdf" data-trans-tooltip="asdfasdf" title="aasdfas">asdf</a>
  </p>
  <p>
    <a href="#" class="tooltip" data-trans="asdfasdf" data-trans-tooltip="asdfasdf"
    title="aasdfas">asdf</a>
  </p>
</div>
    

Preparation code output

<div id="content"> <p> <a href="#" data-trans="asdfasdf" data-trans-tooltip="asdfasdf" title="aasdfas">asdf</a> </p> <p> <a href="#" data-trans="asdfasdf" data-trans-tooltip="asdfasdf" title="aasdfas">asdf</a> </p> <p> <a href="#" data-trans="asdfasdf" data-trans-tooltip="asdfasdf" title="aasdfas">asdf</a> </p> <p> <a href="#" data-trans="asdfasdf" data-trans-tooltip="asdfasdf" title="aasdfas">asdf</a> </p> <p> <a href="#" data-trans="asdfasdf" data-trans-tooltip="asdfasdf" title="aasdfas">asdf</a> </p> <p> <a href="#" data-trans="asdfasdf" data-trans-tooltip="asdfasdf" title="aasdfas">asdf</a> </p> <p> <a href="#" data-trans="asdfasdf" data-trans-tooltip="asdfasdf" title="aasdfas">asdf</a> </p> <p> <a href="#" data-trans="asdfasdf" data-trans-tooltip="asdfasdf" title="aasdfas">asdf</a> </p> <p> <a href="#" data-trans="asdfasdf" data-trans-tooltip="asdfasdf" title="aasdfas">asdf</a> </p> <p> <a href="#" data-trans="asdfasdf" data-trans-tooltip="asdfasdf" title="aasdfas">asdf</a> </p> <p> <a href="#" data-trans="asdfasdf" data-trans-tooltip="asdfasdf" title="aasdfas">asdf</a> </p> <p> <a href="#" data-trans="asdfasdf" data-trans-tooltip="asdfasdf" title="aasdfas">asdf</a> </p> <p> <a href="#" data-trans="asdfasdf" data-trans-tooltip="asdfasdf" title="aasdfas">asdf</a> </p> <p> <a href="#" data-trans="asdfasdf" data-trans-tooltip="asdfasdf" title="aasdfas">asdf</a> </p> <p> <a href="#" data-trans="asdfasdf" data-trans-tooltip="asdfasdf" title="aasdfas">asdf</a> </p> <p> <a href="#" data-trans="asdfasdf" data-trans-tooltip="asdfasdf" title="aasdfas">asdf</a> </p> <p> <a href="#" data-trans="asdfasdf" data-trans-tooltip="asdfasdf" title="aasdfas">asdf</a> </p> <p> <a href="#" data-trans="asdfasdf" data-trans-tooltip="asdfasdf" title="aasdfas">asdf</a> </p> <p> <a href="#" data-trans="asdfasdf" data-trans-tooltip="asdfasdf" title="aasdfas">asdf</a> </p> <p> <a href="#" data-trans="asdfasdf" data-trans-tooltip="asdfasdf" title="aasdfas">asdf</a> </p> <p> <a href="#" data-trans="asdfasdf" data-trans-tooltip="asdfasdf" title="aasdfas">asdf</a> </p> <p> <a href="#" data-trans="asdfasdf" data-trans-tooltip="asdfasdf" title="aasdfas">asdf</a> </p> <p> <a href="#" data-trans="asdfasdf" data-trans-tooltip="asdfasdf" title="aasdfas">asdf</a> </p> <p> <a href="#" data-trans="asdfasdf" data-trans-tooltip="asdfasdf" title="aasdfas">asdf</a> </p> <p> <a href="#" data-trans="asdfasdf" data-trans-tooltip="asdfasdf" title="aasdfas">asdf</a> </p> <p> <a href="#" data-trans="asdfasdf" data-trans-tooltip="asdfasdf" title="aasdfas">asdf</a> </p> <p> <a href="#" data-trans="asdfasdf" data-trans-tooltip="asdfasdf" title="aasdfas">asdf</a> </p> <p> <a href="#" data-trans="asdfasdf" data-trans-tooltip="asdfasdf" title="aasdfas">asdf</a> </p> <p> <a href="#" data-trans="asdfasdf" data-trans-tooltip="asdfasdf" title="aasdfas">asdf</a> </p> <p> <a href="#" data-trans="asdfasdf" data-trans-tooltip="asdfasdf" title="aasdfas">asdf</a> </p> <p> <a href="#" data-trans="asdfasdf" data-trans-tooltip="asdfasdf" title="aasdfas">asdf</a> </p> <p> <a href="#" data-trans="asdfasdf" data-trans-tooltip="asdfasdf" title="aasdfas">asdf</a> </p> <p> <a href="#" class="tooltip" data-trans="asdfasdf" data-trans-tooltip="asdfasdf" title="aasdfas">asdf</a> </p> </div>

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
attr
$('*[title]').each(function() {
  $(this).css('color', 'red');
});
pending…
class
$('.tooltip').each(function() {
  $(this).css('color', 'red');
});
pending…
pure JS
var elms = document.getElementById('content').getElementsByTagName('*'),
    i = 0,
    j = elms.length;

for (; i < j; i++) {
  elms[i].style.color = 'red';
}
pending…
pureJS with querySelectorAll
var elms = document.querySelectorAll('[title]'),
    i = 0,
    j = elms.length;

for (; i < j; i++) {
  elms[i].style.color = 'red';
}
pending…
pureJS with querySelectorAll, class name
var elms = document.querySelectorAll('.tooltip'),
    i = elms.length;

while(i--) {
  elms[i].style.color = 'red';
}
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

asdf

asdf

asdf

asdf

asdf

asdf

asdf

asdf

asdf

asdf

asdf

asdf

asdf

asdf

asdf

asdf

asdf

asdf

asdf

asdf

asdf

asdf

asdf

asdf

asdf

asdf

asdf

asdf

asdf

asdf

asdf

asdf

asdf