-
-
Notifications
You must be signed in to change notification settings - Fork 45.7k
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
Performance: 95% faster Project Euler 187 #10580
Performance: 95% faster Project Euler 187 #10580
Conversation
project_euler/problem_187/sol1.py
Outdated
@@ -68,6 +70,32 @@ def calculate_prime_numbers(max_number: int) -> list[int]: | |||
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]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Describe your change:
Utilizing the
numpy
module, Project Euler 187 now runs 97% faster than the original implementation and is 79% faster than my previous solution.Related issue #8594
Checklist: