05-08-2015 12:39 AM
Hi, is there a way to make the following codes run much faster without changing too much? The goal is in the code.
Solved! Go to Solution.
05-08-2015 01:16 AM - edited 05-08-2015 01:32 AM
@karryli wrote:
Hi, is there a way to make the following codes run much faster without changing too much? The goal is in the code.
Yes, there is. Try the "Sieve of Eratosthenes".
My old prime code does it in less than 50ms on an old laptop. Is that fast enough?
05-08-2015 01:32 AM
I know but it's an assignment, so we are not allowed to use someone else's codes.
05-08-2015 01:35 AM
You are working in UCLA? I think I know who you are. Kyle mentioned you in our workshop before. Hope I can meet you in person!
05-08-2015 01:44 AM - edited 05-08-2015 09:51 AM
OK, looking at the code, you seem to be using the sieve, but there are many very inefficient constructs.
Here are some ideas:
05-08-2015 01:46 AM
Yes, I know Kyle. 😄
05-14-2015 12:27 PM
Thanks so much, Christian.
05-14-2015 12:29 PM
In order to compare code, you also need a good benchmarking procedure. How fast did you get so far? 😄
05-14-2015 12:37 PM
I actually submit a rather navie solution of mine for grades and it takes 0.6s. But I will still study your solution later for a deep understandning of prime numbers. Let me post my submitted soulution here.
05-14-2015 01:17 PM - edited 05-14-2015 01:19 PM
I have not verified the code, but here are some very general comments: