Skip to content

Avoid unnecessary altitude calculations to improve performance#8

Merged
asasine merged 4 commits intoasasine:mainfrom
RossPorter506:main
Mar 8, 2026
Merged

Avoid unnecessary altitude calculations to improve performance#8
asasine merged 4 commits intoasasine:mainfrom
RossPorter506:main

Conversation

@RossPorter506
Copy link
Copy Markdown
Contributor

Hi,

I'm using this library on an embedded device with no floating point hardware (MSP430) and after some profiling I noticed that almost 66% of the runtime of bmp390.pressure() was coming from the (unused) altitude calculation that occurs as part of the internal call to self.measure() (17ms total, altitude took 11ms).

To remedy this I moved the body of measure() into a new public method temperature_pressure() that returns just the temperature and pressure, and updated the other methods to call this instead to avoid any altitude calculations that aren't required.
The new method is public to allow the user to calculate altitude themselves, should they wish to use an approximation or lookup table for performance reasons.

Any comments or edits welcome.

Altitude calculations accounted for ~66% of runtime on my device. Add a temperature_pressure() method to allow the user to e.g. potentially calculate altitude using a cheaper approximation
Copy link
Copy Markdown
Owner

@asasine asasine left a comment

Choose a reason for hiding this comment

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

Hi @RossPorter506 and thank you for the contribution! The changes look good. Could you add unit tests for the new method?

@RossPorter506
Copy link
Copy Markdown
Contributor Author

Sure. Is this what you had in mind?

Copy link
Copy Markdown
Owner

@asasine asasine left a comment

Choose a reason for hiding this comment

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

Looks good, thank you!

@asasine asasine merged commit 765c86e into asasine:main Mar 8, 2026
2 checks passed
@asasine
Copy link
Copy Markdown
Owner

asasine commented Mar 8, 2026

@RossPorter506 your changes have been published in v0.4.3 to https://crates.io/crates/bmp390

@RossPorter506
Copy link
Copy Markdown
Contributor Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants