@Holo,
thanks for this code, it does help me to understand something.
I changed the code a bit to check algorithms with different complexities.
There are some weird results on low number of iterations:
import rhinoscriptsyntax as rs
import random
import time
import math
def func1():
return random.random()
def func2():
return math.factorial(100)
def func3(n=10):
if n <= 1:
return n
return func3(n-1) + func3(n-2)
Total=1000000
onePercent=Total/100
counter = 0
### Just do the calculus
t1=time.time()
for i in range(Total):
counter +=1
#************************#
#value = func1()
#value = func2()
value = func3()
#************************#
print str(time.time()-t1) + " 1. run, no prompting"
tst1 = time.time()-t1
### Calculus with statusupdate based on percent
t1=time.time()
for i in range(Total):
counter +=1
#************************#
#value = func1()
#value = func2()
value = func3()
#************************#
if counter % onePercent == 0:
rs.Prompt( "Processing random value for line "+str(counter)+" of "+str(Total)+" - Value: " +str(value))
print str(time.time()-t1) + " 2. run, prompting every percent"
tst2 = time.time()-t1
### Calculus with statusupdate based on time
t1=time.time()
t2=time.time()
for i in range(Total):
counter +=1
#************************#
#value = func1()
#value = func2()
value = func3()
#************************#
tmpTime= time.time()
if tmpTime-t2> 0.25:
t2=tmpTime
rs.Prompt ( "Processing random value for line "+str(counter)+" of "+str(Total)+" - Value: " +str(value))
print str(time.time()-t1) + " 3. run, prompting every 0.25 second"
tst3 = time.time()-t1
dif1 = tst2 - tst1
dif2 = tst3 - tst1
print "difference 1: {} sec, difference 2: {} sec".format(dif1,dif2)
Results:
1000 iterations
Algorithm 1
0.00499725341797 1. run, no prompting
0.137016296387 2. run, prompting every percent
0.00799560546875 3. run, prompting every 0.25 second
difference 1: 0.122016906738 sec, difference 2: -0.00700378417969 sec
Algorithm 2
0.0290069580078 1. run, no prompting
0.80908203125 2. run, prompting every percent
0.0179977416992 3. run, prompting every 0.25 second
difference 1: 0.779075622559 sec, difference 2: -0.0120086669922 sec
Algorithm 3
0.0489959716797 1. run, no prompting
0.157005310059 2. run, prompting every percent
0.0439910888672 3. run, prompting every 0.25 second
difference 1: 0.0980224609375 sec, difference 2: -0.0139846801758 sec
100000 iterations:
Algorithm 1:
0.115020751953 1. run, no prompting
0.325035095215 2. run, prompting every percent
0.245025634766 3. run, prompting every 0.25 second
difference 1: 0.210021972656 sec, difference 2: 0.130012512207 sec
Algorithm 2:
1.58716583252 1. run, no prompting
2.43523406982 2. run, prompting every percent
1.73817443848 3. run, prompting every 0.25 second
difference 1: 0.848068237305 sec, difference 2: 0.152008056641 sec
Algorithm 3:
4.56545257568 1. run, no prompting
4.73948669434 2. run, prompting every percent
4.65445709229 3. run, prompting every 0.25 second
difference 1: 0.174034118652 sec, difference 2: 0.0890045166016 sec
1000000 iterations
Algorithm 1:
1.04610443115 1. run, no prompting
1.68716430664 2. run, prompting every percent
2.24222564697 3. run, prompting every 0.25 second
difference 1: 0.641059875488 sec, difference 2: 1.19612121582 sec
Algorithm 2:
15.4585494995 1. run, no prompting
16.9316940308 2. run, prompting every percent
17.3017349243 3. run, prompting every 0.25 second
difference 1: 1.47314453125 sec, difference 2: 1.84318542480 sec
Algorithm 3:
38.4748458862 1. run, no prompting
39.2499237061 2. run, prompting every percent
39.9949951172 3. run, prompting every 0.25 second
difference 1: 0.77507019043 sec, difference 2: 1.52114868164 sec