Open orestesgaolin opened 2 days ago
Yeah, I saw that post last night. PRs are welcome, though I would not necessarily accept all of the recommended changes because some are things that other fundamentally change the program (adding a variable).
Would you say that this change would not be acceptable?
for (int i = 0; i < 10000; i++) {
// 10k outer loop iterations
+ a[i]; /* <- THIS LINE WAS ADDED */
for (int j = 0; j < 100000; j++) {
// 100k inner loop iterations, per outer loop iteration
a[i] = a[i] + j % u; // Simple sum
That's an interesting one, as it doesn't actually change any of the other logic.
I would lean towards not accepting it. One reason why: Your average or even quite skilled programmer would not put that there. Only someone who knows the compiler and what optimizations it is and isn't capable of would add that. I'd want the compiler to be smart enough to "figure it out for me" without having to code things in unusual ways.
One of the Dart language maintainers Slava Egorov looked at this benchmark and has suggested couple of improvements. The blog post is available on his website: https://mrale.ph/blog/2024/11/27/microbenchmarks-are-experiments.html. In his attempt he made it execute almost as fast as the C implementation:
I think it would be amazing to implement these suggestions with a proper credit.