1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
| import time
def foo1():
with open('mots.txt', 'r') as f:
for ligne in iter(f):
l = ligne
def foo2():
f=open("mots.txt", "r")
while True:
ligne=f.readline()
if ligne == "":
break
l = ligne
f.close()
def foo3():
f = open("mots.txt", "r")
for ligne in iter(f):
l = ligne
f.close()
def foo4():
f=open("mots.txt", "r")
for ligne in f.readlines():
l = ligne
f.close()
def foo5():
f=open("mots.txt", "r")
for ligne in f:
l = ligne
f.close()
def foo6():
with open('mots.txt', 'r') as f:
while True:
ligne=f.readline()
if ligne == "":
break
l = ligne
ts = time.time()
foo1()
print("foo1 : {} sec".format(time.time()-ts))
ts = time.time()
foo2()
print("foo2 : {} sec".format(time.time()-ts))
ts = time.time()
foo3()
print("foo3 : {} sec".format(time.time()-ts))
ts = time.time()
foo4()
print("foo4 : {} sec".format(time.time()-ts))
ts = time.time()
foo5()
print("foo5 : {} sec".format(time.time()-ts))
ts = time.time()
foo6()
print("foo6 : {} sec".format(time.time()-ts)) |
Partager