Closed SadToBeNep closed 4 months ago
I'll do some benchmarks on my own, this is a feature I am working on currently, and get back to you...
Can you share the code you conducted the benchmarks on? Have you implemented bound-checks?? Since I am only getting comparable performance without bound-checking, what of course is dangerous.
I have been unable to achieve said performance improvements.
However ,I will improve the performance by utilising vectorizationd (SIMD!).
What?
I did some benchmarks on the already implemented
Sum()
function and tried to improve it's speed a bit (results bellow)Why?
I did the benchmarks as part of my learning about C# code optimizations, and from that I know that the
for
loops can be sometimes slowHow we could improve it?
Well, there are obviously a lot of ways to do that, I think as an early development suggestion, it would be good if we used
foreach
instead of basicfor
loops even tho this isn't the biggest performance improvement, unrolling the loop is much faster, but again, for the sake of maintainability simply changingfor
toforeach
is enoughResults of tests
Some explanation
Even tho the compiler does some optimization on the loop, we can achieve much better performance by implementing the loop in a way, where it's adding together
source[x]+source[x+1]+source[x+3]...
Using this method as we can see the improvements with really small lists of numbers(100) the loop is almost twice as fast, and after that it keeps a 20-30% faster numbers As for my suggestion of changingfor
toforeach
the improvement are around 10% stable regardless of the size, and again maintaining the simpler solution is easierCan try to implement it by myself if needed