Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cpr_nl invalid values/underflow panic #4

Merged
merged 3 commits into from
Jan 23, 2021

Conversation

wiseman
Copy link
Contributor

@wiseman wiseman commented Jan 22, 2021

Switched cpr_nl to a table lookup, fixing the problem of it returning an invalid value leading to a panic. It's also considerably faster. This fixes issue #3.

cpr_nl_high_lat         time:   [10.764 ns 10.795 ns 10.830 ns]
                        change: [-40.716% -39.922% -39.255%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 3 outliers among 100 measurements (3.00%)
  2 (2.00%) high mild
  1 (1.00%) high severe

cpr_nl_low_lat          time:   [2.2473 ns 2.2617 ns 2.2767 ns]
                        change: [-89.576% -89.479% -89.386%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 6 outliers among 100 measurements (6.00%)
  3 (3.00%) low mild
  3 (3.00%) high mild

cpr_nl was returning 0 in some cases, which could lead to panics. This
change switches cpr_nl from a trigonometry-based implementation
to (essentially) a table lookup.

I added a couple unit tests, and a criterion benchmark for cpr_nl to
validate the table-based speedup.

On my machine this version is, in the worst case situation, 40%
faster. In the best case it's 89% faster.

```
cpr_nl_high_lat         time:   [10.764 ns 10.795 ns 10.830 ns]
                        change: [-40.716% -39.922% -39.255%] (p = 0.00 < 0.05)
                        Performance has improved.

cpr_nl_low_lat          time:   [2.2473 ns 2.2617 ns 2.2767 ns]
                        change: [-89.576% -89.479% -89.386%] (p = 0.00 < 0.05)
                        Performance has improved.
```

Fixes issue asmarques#3.
@wiseman wiseman changed the title Cpr underflow Fix cpr_nl invalid values/underflow panic Jan 22, 2021
@asmarques asmarques merged commit ff3ecaf into asmarques:master Jan 23, 2021
@asmarques
Copy link
Owner

Thanks. Even with fuzzing it is difficult to catch all the corner cases. The lookup table also seems like a much more robust solution.

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.

None yet

2 participants