Ben de simdiye kadar onerilen kodlarin zamanini olctum.
def cevap_1():
toplam = 0
for i in range(1,1000):
if i % 3 == 0:
toplam += i
if i % 5 == 0:
toplam += i
if i % 15 == 0:
toplam -= i
return toplam
def cevap_2():
toplam=sum(3*i for i in range(1,334)) + sum(5*i for i in range(1,200)) - sum(15*i for i in range(1,67))
return toplam
def cevap_3():
toplam = sum(i for i in range(1000) if (i % 3 == 0 or i % 5 == 0))
return toplam
if __name__ == '__main__':
import timeit
print("Cevap 1 : ", cevap_1() , "Zaman : ",timeit.timeit("cevap_1()", setup="from __main__ import cevap_1",number=10000) )
print("Cevap 2 : ", cevap_2() , "Zaman : ",timeit.timeit("cevap_2()", setup="from __main__ import cevap_2",number=10000) )
print("Cevap 3 : ", cevap_3() , "Zaman : ",timeit.timeit("cevap_3()", setup="from __main__ import cevap_3",number=10000) )
###################################################
# Cevap 1 : 233168 Zaman : 2.4881908050738275 #
# Cevap 2 : 233168 Zaman : 0.5679739599581808 #
# Cevap 3 : 233168 Zaman : 1.5673820079537109 #
###################################################