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

[Improvement] Faster _ecg_findpeaks_elgendi #943

Merged
merged 1 commit into from
Jan 10, 2024

Conversation

purpl3F0x
Copy link
Contributor

@purpl3F0x purpl3F0x commented Jan 4, 2024

Description

Optimize _ecg_findpeaks_elgendi in those areas of the code:

  1. blocks could be just a bool array
  2. Detection of start/end of block by only comparing prev vs cur (blocks[i-1], blocks[i]) value. (about 2x faster) (even better when combined with "1")
  3. Use enumerate(zip(...)) for iterating the array, (gives a small performance -but measurable- improvement)
  4. Move some thresholds outisde of the loop, not to get calculated at each iteration

Checklist

Here are some things to check before creating the PR. If you encounter any issues, do let us know :)

  • I have read the CONTRIBUTING file.
  • My PR is targeted at the dev branch (and not towards the master branch).
  • I ran the CODE CHECKS on the files I added or modified and fixed the errors.
  • I have added the newly added features to News.rst (if applicable)

Signed-off-by: Stavros Avramidis <[email protected]>
@DominiqueMakowski
Copy link
Member

For some reason it fails the tests

@purpl3F0x
Copy link
Contributor Author

purpl3F0x commented Jan 10, 2024

It seems to be passing this time., worried-I did some copy-pasta typo on the variables. but seems ok now 🤷

EDIT: it seemes an unrelated .tar file was broken during the setup

@DominiqueMakowski
Copy link
Member

Out of curiosity, do you have a benchmark do show how much time we shave wit the version?

@purpl3F0x
Copy link
Contributor Author

Out of curiosity, do you have a benchmark do show how much time we shave wit the version?

I did some measurments, mainly on individual parts of the code. Don't have the excact numbers in hand, but:

  • the comparison optimization is 2x faster on average&worst case since it gets narrowed down from up to 4 to up to 2.
  • On using the bool array, without taking into account the reduced memory footprint + not traversing the loop for finding it's max value (why was this needed??)
    image

@DominiqueMakowski
Copy link
Member

Nice job, thanks!

@DominiqueMakowski DominiqueMakowski changed the title Optimise _ecg_findpeaks_elgendi [Improvement] Optimise _ecg_findpeaks_elgendi Jan 10, 2024
@DominiqueMakowski DominiqueMakowski changed the title [Improvement] Optimise _ecg_findpeaks_elgendi [Improvement] Faster _ecg_findpeaks_elgendi Jan 10, 2024
@DominiqueMakowski DominiqueMakowski merged commit 2a1c621 into neuropsychology:dev Jan 10, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants