But still just 85% of a conventional cached loop (34 vs 40 ops/s per the last test).
senfiaj•1d ago
The author here, I ran another test here https://jsben.ch/QCXCY . https://jsbenchmark.com/ seems to have issues with longer running code.
1500 repeats, for me for-of is now on par with classic for. As I said, for-of loops are not optimized as easily and reliably because v8 has to prove certain things to be able to do so. For-of's default is iterator protocol, and its more sensitive to deoptimization.
phillipseamore•15h ago
Got similar results but then tested on an older win10 i5 system (8+ years old?) chrome 145 and get variable results but classic is always about twice foreach or forof and foreach often performs 2x better than forof. I fear this might be more connected to CPUs than anything.
senfiaj•3m ago
Weird. If V8 produces different optimized codes for different loops, this might be true on some CPUs. But when I get 100% convergence when increasing the repeats, this becomes a bit suspicious. Also, it might be some timing difference related to initial warmup or some adjustments in V8 for specific CPUs (including some power saving). I also ran on Pixel 3a , both classic and for-of were 100%, foreach was ~9% (on Windows 11 and AMD Ryzen 5000U was the same, except foreach was 62.96%).
I created another benchmark https://jsben.ch/sdaEM . The difference is that doSomethingWithValue now assigns the passed value to some variable. I think the optimizer could still notice that the function was dummy and do weird things, but not sure 100%. So I store in a variable to prevent this. Now the tests run slower, but still both classic and for-of tend to be 100%. forEach is sometimes slower, sometimes on par with the other 2 (on both AMD Ryzen 5000U Laptop and Pixel 3a).
Could you please run this test on your mentioned machine? Also could you gradually increase the number of repeats in each test case and see if there is some convergence? Also make sure the tab and the browser window are active during the benchmark. Otherwise the browser / OS might give less priority to the task. And BTW, can you also test on Chrome 143 and even Chrome 144 (it will be released tomorrow)?
phillipseamore•1d ago
senfiaj•1d ago
phillipseamore•15h ago
senfiaj•3m ago
I created another benchmark https://jsben.ch/sdaEM . The difference is that doSomethingWithValue now assigns the passed value to some variable. I think the optimizer could still notice that the function was dummy and do weird things, but not sure 100%. So I store in a variable to prevent this. Now the tests run slower, but still both classic and for-of tend to be 100%. forEach is sometimes slower, sometimes on par with the other 2 (on both AMD Ryzen 5000U Laptop and Pixel 3a).
Could you please run this test on your mentioned machine? Also could you gradually increase the number of repeats in each test case and see if there is some convergence? Also make sure the tab and the browser window are active during the benchmark. Otherwise the browser / OS might give less priority to the task. And BTW, can you also test on Chrome 143 and even Chrome 144 (it will be released tomorrow)?