Run details:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36
Chrome 109
Linux
Desktop
2 years ago
Test name Executions per second
A 8.9 Ops/sec
B 22.3 Ops/sec
Script Preparation code:
x
 
var x = 0;
function doSomething(x) {
  return x++;
}
Tests:
  • A

     
    for(var i=0; i < 1000000; i++) {
      (function(someValue) {
        return x++;
      })(i);
    }
  • B

     
    for(var i=0; i < 1000000; i++) {
      doSomething(i);
    }