I have some small piece of software that calculates the number of factors of each triangle number to see what is the first one of them has more than X number of factors (yes, it's a projecteuler problem, number 12,, although i didn't solve it yet)... as am trying making X some random values to see what the code does and in how much time, I noticed something strange (to me at least): until X=47 the execution time increases in obviously normal way, but when X = 48 it increases more than normal, and function calls are much greater than the rate, it (explodes) if I would say that.. why does it do that??
the code:
def fac(n): c=0 for i in range (1,n+1): if n%i==0: c=c+1 return c n=1 while True: summ=0 for i in range (1,n+1): summ=summ+i if fac(summ)>X: break n=n+1 print summ and when profiling:
when X=45 : 314 function calls in 0.027 CPU seconds when X=46 : 314 function calls in 0.026 CPU seconds when X=47 : 314 function calls in 0.026 CPU seconds when X=48 : 674 function calls in 0.233 CPU seconds when X=49 : 674 function calls in 0.237 CPU seconds I assume that if I continued I would meet other points that system calls increases and time increases suddenly, and previously there were points like that but time was so small so it did't matter so much.. Why function calls suddenly increases?? Isn't it supposed just to call the function one more time for the new value??
P.S. am using cProfile as a profiler, and X in the code here is just for demonstration, I write the value directly in the code... thank you in advance...
c=c+1does indeed accumulate in memory. However I admit that it's a very small accumulation. I repeat: it's a guess.