myforeach4945gh49g

JavaScript performance comparison

Test case created by csorfab

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  Array.prototype.myForEach = function(cb) {
  for(let i = 0; i < this.length; i++) {
  cb(this[i], i, this)
  }
  }
  
  const a = Array(100000).fill(0).map((v, i) => i)

};
</script>

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
for loop
let sum = 0
for(let i = 0; i < a.length; i++) {
sum += a[i]
}
console.log(sum)
pending…
for of
let sum = 0
for(let n of a) {
sum += n
}
console.log(sum)
pending…
forEach
let sum = 0
a.forEach(n => sum += n)
console.log(sum)
pending…
myForEach
let sum = 0
a.myForEach(n => sum += n)
console.log(sum)
pending…
cachedLength
let sum = 0
for(let i = 0, l = a.length; i < l; i++) {
sum += a[i]
}
console.log(sum)
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