记录求999990000—10000000000之间素数的运算时间。
import time def isPrime(n): for i in range(2,n): if n%i==0: return False else: return True strPrime=" " t=time.clock() for j in range(99999900000,10000000000): if isPrime(j): strPrime=strPrime + str (j) +"," print("Time Used:{}".format(time.clock()-t))
import time def isPrime(n): for i in range(2,n/2+1): if n%i==0: return False else: return True strPrime=" " t=time.clock() for j in range(99999900000,10000000000): if isPrime(j): strPrime=strPrime + str (j) +"," print("Time Used:{}".format(time.clock()-t))
Time Used:4.444444444444444e-06
Time Used:4.444444444444071e-06
>>