forEach vs map

Benchmark created by adrianrozanski on


Preparation HTML

<a href="#" class="waiting foo">test</a> <a href="#" class="switching foo">test</a>

Setup

let arr = ['waiting', 'switching'];

Test runner

Ready to run.

Testing in
TestOps/sec
forEach
arr.forEach(function(num, index){
  document.getElementsByClassName(arr[index])[0].classList.remove('foo');
})
ready
map
arr.map(function(item){
  document.getElementsByClassName(item)[0].classList.remove('foo');
})
ready

Revisions

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

  • Revision 1: published by adrianrozanski on