PDA

View Full Version : Python 3 --> Timing factorials.



danbaron
18-12-2011, 12:55
Here, in Python 3, are the times to find n!, for various values of n, on my (slow) computer.


' code -------------------------------------------------------------------------------------------

# fact.py

import time

def fact(n):
fact = 1
for i in range(1,n+1):
fact *= i
return fact

print()
print("n! seconds")
for i in range(10000,210000,10000):
t1 = time.clock()
f = fact(i)
t2 = time.clock()
print("{0:06d} {1:08.3f}".format(i,t2-t1))
print()

' output -----------------------------------------------------------------------------------------

C:\Users\root\Desktop\py>python fact.py

n! seconds
010000 0000.189
020000 0000.796
030000 0001.931
040000 0004.924
050000 0009.093
060000 0014.278
070000 0021.162
080000 0027.877
090000 0036.518
100000 0046.368
110000 0056.992
120000 0068.359
130000 0081.301
140000 0097.560
150000 0112.566
160000 0129.895
170000 0149.381
180000 0171.193
190000 0195.403
200000 0218.713

C:\Users\root\Desktop\py>

Petr Schreiber
18-12-2011, 15:44
Hi Dan,

do you think you could write down your PC specs (CPU type & frequency, amount of RAM, OS) to get better idea?


Thanks,
Petr

danbaron
18-12-2011, 21:32
Here is what I could find, Petr.

Some of this stuff doesn't mean anything to me, maybe it does to you.

------------------------------------------------

emachines EL1200-07w

Windows Home Premium

Service Pack 1

AMD Athlon Processor 2650e 1.60 GHz

RAM: 2.00 GB (1.75 GB usable)

32-bit Operating System

Petr Schreiber
19-12-2011, 10:14
Thanks Dan, exactly what I needed!


Petr

zak
19-12-2011, 11:26
i got those timing with python 2.6
100000 0031.655
110000 0038.909
120000 0047.235
130000 0055.943
140000 0065.706
OS is windows xp /sp3
my cpu is pentium D 3.0 GHz, 3GB ram DDR2.
my cpu have a mark 814 in passmark cpu, http://www.cpubenchmark.net/cpu_list.php
while Intel Core i7 995X @ 3.60GHz Passmark is 10945. of course add to that the other capabilities of those mighty processors compared to my old cpu.
we can see that the i3, i5, i7 are better.