@Cristian Traìna Node does not allow to skip empty loops. These optimizations are allowed only in compiled languages like Pascal or C/C++ with flags like -O2
.
For this program
var max=process.argv[2];
for(var i=0;i<=max;i++){} // with let results is the same
We can get the following dependency of time of execution from a number of loops. It is a LogLog chart. The first flat area it domain when dominating part of execution time is starting of NodeJs. After 1M loops, you can see that increasing number of iteration scaling with time linearly. Highest measurement takes about 1000 seconds so definitely, V8 does not skip the empty loop.

(source: gustawdaniel.pl)
Coming back to script from question:
function-call: 154.878662109375ms
in-function: 153.7490234375ms
function-call: 154.183ms
in-function: 152.907ms
function-call: 156 ms debugger eval code:4:3
in-function: 1519 ms
function-call: 158.954345703125ms
in-function: 153.663818359375ms
function-call: 153.548095703125ms
in-function: 153.755126953125ms
function-call: 154.34814453125ms
in-function: 154.729248046875ms
The computer of my Friend tests:
function-call: 3 496,6 ms
in-function: 2 330,9 ms
function-call: 70.69580078125ms
in-function: 70.43310546875ms
So now it seems to be a problem with Firefox and Edge.
Any of these browsers except Firefox and Edge uses V8 engine. Firefox is described here:
https://www.digitaltrends.com/web/mozilla-firefox-new-browser-engine-quantum-2017/
and uses Quantum Flow:
.
Edge team think about adopting Chromium engine
https://www.pcmag.com/news/365345/microsofts-edge-browser-to-adopt-googles-chromium-engine
From this article
https://blog.mozilla.org/blog/2018/12/06/goodbye-edge/
We can see that only Chromium from Google
and Gecko Quantum from Mozilla
will be supported in the future.
If anyone has access to Safari or Edge, please append tests.