Weird loop optimizations with C++ #643
DelinWorks
started this conversation in
General
Replies: 1 comment 4 replies
-
Does the test result is from release build? |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
One question about cpp is when I was working on improving the particle system, there were comments saying that separating loops to fill each data field was the best optimization, like:

And then I was told that

std::fill_n
is even better for static values, like:Soo I've ran a test and the results were shocking:
Why is the method of combining the loops into a single one the fastest? even though people say that separating loops is faster because cache hit rates are better.
A single loop is something like this:

Can someone explain to me why is this the case?
The code:
Beta Was this translation helpful? Give feedback.
All reactions