b = time.clock()
execute() #processing
a = time.clock() - b
Modified source
import time
def hoge_while(h):
while h % 15 == 0: return "KinokoTakenoko"
while h % 3 == 0: return "Kinoko"
while h % 5 == 0: return "Takenoko"
return ""
def hoge_if(h):
result = ""
if h % 3 == 0: result += "Kinoko"
if h % 5 == 0: result += "Takenoko"
return result
def loop(hoge_list):
i = 1
while i <= 10000000:
i, hoge_list[i-1]
i += 1
before = time.clock()
loop([hoge_if(i) for i in range(1, 10000001)])
print time.clock() -before
before = time.clock()
loop([hoge_while(i) for i in range(1, 10000001)])
print time.clock() -before
Recommended Posts