Run details:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:95.0) Gecko/20100101 Firefox/95.0
Firefox 95
Windows
Desktop
3 years ago
Test name Executions per second
querySelectorAll foreach 647421.9 Ops/sec
getElementsByClassName [].forEach.call() 923590.5 Ops/sec
Array.prototype 906438.9 Ops/sec
Array.from 470017.9 Ops/sec
HTML Preparation code:
AخA
 
1
<div class="test"></div>
2
<div class="test"></div>
3
<div class="test"></div>
4
<div class="test"></div>
5
<div class="test"></div>
6
<div class="test"></div>
7
<div class="test"></div>
8
<div class="test"></div>
9
<div class="test"></div>
Tests:
  • querySelectorAll foreach

     
    var test = document.querySelectorAll(".test");
    test.forEach(el => {
      var t = el;
    });
  • getElementsByClassName [].forEach.call()

     
    var test = document.getElementsByClassName("test");
    [].forEach.call(test, el => {
      var t = el;
    });
  • Array.prototype

     
    var test = document.getElementsByClassName("test");
    Array.prototype.forEach.call(test, el => {
      var t = el;
    });
  • Array.from

     
    var test = document.querySelectorAll(".test");
    Array.from(test).forEach(el => {
      var t = el;
    });