You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
Refering to "DspUtilities.cpp, multiple copies of float rand11 = (((float)rand() / RAND_MAX) * 2.f - 1.f);
a.) Refactor to a function rand11()
b.) Optimize expression to make it less operations
b.1) Create a Constand RAND_MAX_HALF = RAND_MAX / 2
b.2) Make the expression: (((float)rand() / RAND_MAX_HALF) - 1.f);
Take it as a suggestion please: Computer arithmetics has it's subtleties. Not 100% sure whether the "optimized" version as suggested is numerically the same... could be that rounding error might make the range not [ -1, 1 ].
To Reproduce
Stare at the code and do arithmetics ;-)
Expected behavior
Runs with less cpu cycles on every call to any of the funcions in DspUtilities that use the same copy of code.
Screenshots
/
Desktop (please complete the following information):
/
Additional context
/
The text was updated successfully, but these errors were encountered:
Did you focus on this code because of a profile result or just inspection?
I’m surprised the compiler doesn’t do this constant transform since rand max and 2f are constants. Did you peek at the assembly output to check that? If it doesn’t introducing a constexpr halfrandmax could save a mul
If you do make the new function change the new function you propose should be inline and header visible and we would want to check that the ejected code inlines properly on Mac win and lin. Don’t want an extra out of line call!
Describe the bug
Refering to "DspUtilities.cpp, multiple copies of float rand11 = (((float)rand() / RAND_MAX) * 2.f - 1.f);
a.) Refactor to a function rand11()
b.) Optimize expression to make it less operations
b.1) Create a Constand RAND_MAX_HALF = RAND_MAX / 2
b.2) Make the expression: (((float)rand() / RAND_MAX_HALF) - 1.f);
Take it as a suggestion please: Computer arithmetics has it's subtleties. Not 100% sure whether the "optimized" version as suggested is numerically the same... could be that rounding error might make the range not [ -1, 1 ].
To Reproduce
Stare at the code and do arithmetics ;-)
Expected behavior
Runs with less cpu cycles on every call to any of the funcions in DspUtilities that use the same copy of code.
Screenshots
/
Desktop (please complete the following information):
/
Additional context
/
The text was updated successfully, but these errors were encountered: