I wanna evaluate how large prime numbers my computer work at most 60 seconds. Of course, I can evalutate this manaully e.g. by trying different values. However, can I do this differently, e.g. by setting the time?
1 Answer
This should do what you want. You can change the argument of PrimeQ
based on the granularity you are looking for VS the time you want to spend. TimeConstrainted
aborts if the computation takes more than 60 seconds, CheckAbort
returns Print[n]
if PrimeQ
took more than 60 seconds.
n = 10;
While[Not@CheckAbort[TimeConstrained[PrimeQ[10^(100*n) + 1], 60]
, Print[n]], n++]
Returns n=176
for 10 seconds and n=304
for 60 seconds on my laptop.
You can check: PrimeQ[10^(100*304) + 1] // AbsoluteTiming
returns 68 seconds (and False
). If you are looking specifically for primes, you can adapt the above code.
{10^2000, 10^2000}
. Also - what is your end goal? Generating prime numbers? Filtering them afterwards? $\endgroup${9.45313, \ 6874090616771610210074487399211060171147764570196238070783173836677958\ 1619995425908424621945207150352924177002190160746774878511809371120288\ 910835110915978986241...}
on my comp. $\endgroup$