The running time of the following program(which is inside function prime)is 110.726383227 seconds
If I run the same program without wrapping it in a function(prime) it's running time is 222.006502634 seconds
I made a significant performance improvement by wrapping it in a function.
still is there any possibility increase the efficiency of this program ?
# This is a program to find sum of prime numbers till 2 billion
def prime():
import time
start_time = time.clock()
num = 2
j=1
tot_sum = 0
for num in xrange(2,2000000):
count = 0
for j in xrange(1,int(num**0.5)+1): # checking from 1 to sqrt(n)+1
if(num % j == 0):
count = count+1
if(count == 1):
tot_sum = tot_sum + num
print "total sum is %d" % tot_sum
print time.clock() - start_time, "seconds"