Closed
Description
Library/API/IoT binding
System.Math
Visual Studio version
No response
.NET nanoFramework extension version
No response
Target name(s)
No response
Firmware version
No response
Device capabilities
No response
Description
While benchmarking the System.Math function I noticed that Math.Max(float)
and Math.Min(float)
are 3x slower than Math.Max(double)
and Math.Min(double)
.
While reviewing the code I see that both of the float overloads just delegate down to the double overload and cast the result to a float. I'm assuming this is the root cause of the performance difference.
How to reproduce
Run the benchmarks at https://github.com/CoryCharlton/CCSWE.nanoFramework.Math
Expected behaviour
Similar, if not faster, performance.
Screenshots
No response
Sample project or code
No response
Aditional information
Console export: MaxBenchmarks benchmark class.
| MethodName | ItterationCount | Mean | Min | Max |
| --------------------------------------------------------------------------- |
| Max_Double_System | 250 | 13.12 ms | 10 ms | 20 ms |
| Max_Float_System | 250 | 29.32 ms | 20 ms | 40 ms |
Console export: MinBenchmarks benchmark class.
| MethodName | ItterationCount | Mean | Min | Max |
| --------------------------------------------------------------------------- |
| Min_Double_System | 250 | 11.2 ms | 0 ms | 20 ms |
| Min_Float_System | 250 | 35.64 ms | 20 ms | 50 ms |