Skip to content

Improve min max performance and IEEE compliance#151

Merged
josesimoes merged 14 commits into
nanoframework:mainfrom
CoryCharlton:improving_min_max
Nov 9, 2023
Merged

Improve min max performance and IEEE compliance#151
josesimoes merged 14 commits into
nanoframework:mainfrom
CoryCharlton:improving_min_max

Conversation

@CoryCharlton

Copy link
Copy Markdown
Member

Description

  • Reduce IsNan checks to improve performance
  • Fix Min not returning NaN in all cases it should
  • Implement Min(float) and Max(float)

Motivation and Context

How Has This Been Tested?

  • On device
  • Unit tests

Screenshots

Types of changes

  • Improvement (non-breaking change that improves a feature, code or algorithm)
  • Bug fix (non-breaking change which fixes an issue with code or algorithm)
  • New feature (non-breaking change which adds functionality to code)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Config and build (change in the configuration and build system, has no impact on code or features)
  • Dependencies (update dependencies and changes associated, has no impact on code or features)
  • Unit Tests (add new Unit Test(s) or improved existing one(s), has no impact on code or features)
  • Documentation (changes or updates in the documentation, has no impact on code or features)

Checklist:

  • My code follows the code style of this project (only if there are changes in source code).
  • My changes require an update to the documentation (there are changes that require the docs website to be updated).
  • I have updated the documentation accordingly (the changes require an update on the docs in this repo).
  • I have read the CONTRIBUTING document.
  • I have tested everything locally and all new and existing tests passed (only if there are changes in source code).
  • I have added new tests to cover my changes.

@CoryCharlton

Copy link
Copy Markdown
Member Author

Look like the build failure is because the firmware changes need to be merged first.

@CoryCharlton

Copy link
Copy Markdown
Member Author

For reference:

Before...

| MethodName | ItterationCount | Mean                  | Min   | Max   |
| -------------------------------------------------------------------- |
| Max_Double | 250             | 8.7599999999999998 ms | 0 ms  | 10 ms |
| Max_Float  | 250             | 43.52 ms              | 30 ms | 50 ms |
| Max_Int    | 250             | 22.199999999999998 ms | 20 ms | 30 ms |
| Min_Double | 250             | 13.32 ms              | 10 ms | 20 ms |
| Min_Float  | 250             | 28.959999999999999 ms | 20 ms | 40 ms |
| Min_Int    | 250             | 13.72 ms              | 10 ms | 20 ms |

After...

| MethodName | ItterationCount | Mean     | Min   | Max   |
| ------------------------------------------------------- |
| Max_Double | 250             | 6.48 ms  | 0 ms  | 10 ms |
| Max_Float  | 250             | 7.04 ms  | 0 ms  | 10 ms |
| Max_Int    | 250             | 7.48 ms  | 0 ms  | 10 ms |
| Min_Double | 250             | 7 ms     | 0 ms  | 10 ms |
| Min_Float  | 250             | 7.8 ms   | 0 ms  | 10 ms |
| Min_Int    | 250             | 10.44 ms | 10 ms | 20 ms |

@josesimoes

Copy link
Copy Markdown
Member

Look like the build failure is because the firmware changes need to be merged first.

That is correct. Currently a PR on another repo that depends on nanoCLR library has to have that one merged before it can be consumed in the pipeline.

@josesimoes josesimoes left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Impressive! Thanks for all the work on this.
Great usage of the benchmark library! 😉

Overall all good. We're better moving the Max and Min to mscorlib.
Even if that's not release rigth away. It won't break anything.

Comment thread nanoFramework.System.Math.Benchmark/Program.cs Outdated
Comment thread nanoFramework.System.Math/Math.cs Outdated
Comment thread nanoFramework.System.Math/Math.cs Outdated
Comment thread nanoFramework.System.Math/Math.cs Outdated
Comment thread nanoFramework.System.Math/Math.cs Outdated
Comment thread Tests/MathUnitTests/Max_Tests.cs Outdated
@josesimoes josesimoes enabled auto-merge (squash) November 9, 2023 03:40
@josesimoes josesimoes disabled auto-merge November 9, 2023 03:40
@josesimoes josesimoes merged commit 79c817a into nanoframework:main Nov 9, 2023
@CoryCharlton CoryCharlton deleted the improving_min_max branch November 10, 2023 22:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Math.Min(double/float) do not handle NaN correctly Math.Max(float) and Math.Min(float) are 3x slower than the double overloads

3 participants