Performance: 95% faster Project Euler 187#10580
Closed
ManpreetXSingh wants to merge 9 commits intoTheAlgorithms:masterfrom
ManpreetXSingh:reoptimize-euler-187
Closed
Performance: 95% faster Project Euler 187#10580ManpreetXSingh wants to merge 9 commits intoTheAlgorithms:masterfrom ManpreetXSingh:reoptimize-euler-187
ManpreetXSingh wants to merge 9 commits intoTheAlgorithms:masterfrom
ManpreetXSingh:reoptimize-euler-187
Conversation
10 tasks
13 tasks
dhruvmanila
approved these changes
Oct 29, 2023
project_euler/problem_187/sol1.py
Outdated
| return [2] + [2 * i + 1 for i in range(1, max_number // 2) if is_prime[i]] | ||
|
|
||
|
|
||
| def np_calculate_prime_numbers(max_number: int) -> list[int]: |
Member
There was a problem hiding this comment.
Is it possible to make this as a helper function in a common module as I see it being used in your other PR as well or maybe add it in maths/ and re-use it here or (assuming that there's already similar function in maths/) re-use an existing implementation?
Contributor
Author
There was a problem hiding this comment.
Hi @dhruvmanila,
Please see if I added the helper function correctly.
Also I found out that the benchmark in the file maths/prime_numbers.py was not working as expected, so I fixed it.
I noticed that the functions yield the result, so they calculated nothing in the benchmark function.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Describe your change:
Utilizing the
numpymodule, Project Euler 187 now runs 97% faster than the original implementation and is 79% faster than my previous solution.Related issue #8594
Checklist: