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 61 62 63 64 65 66 67 68
| from timeit import Timer
def fonction1():
f = open('fich5col','r')
lif = f.read().replace('\n','\t').split('\t')
f.close()
Freq = [ lif[k] for k in range(0,len(lif),5) ]
ModS21 = [ lif[k] for k in range(3,len(lif),5) ]
def fonction2():
f = open('fich5col','r')
lif = f.read().replace('\t','\n').splitlines()
f.close()
Freq = [ lif[k] for k in range(0,len(lif),5) ]
ModS21 = [ lif[k] for k in range(3,len(lif),5) ]
def fonction3():
Freq = []
ModS21 = []
f = open('fich5col','r')
for ligne in f:
tb = ligne.split('\t')
Freq.append(tb[0])
ModS21.append(tb[3])
f.close()
ITERATIONS = 10
REPETITIONS = 25
print "Résultats sur",REPETITIONS,"répétitions de",ITERATIONS,"itérations\n\n"
titi = Timer('fonction1()', 'from __main__ import fonction1')
res1 = titi.repeat(REPETITIONS,ITERATIONS)
sum = 0
for y in res1:
sum = sum + y
print "\n\n\tfonction1: lif = f.read().replace('\\n','\\t').split('\\t')\n"
print 'temps minimal =',min(res1)," secondes"
print " temps moyen =",sum/REPETITIONS," secondes"
titi = Timer('fonction2()', 'from __main__ import fonction2')
res2 = titi.repeat(REPETITIONS,ITERATIONS)
sum = 0
for y in res2:
sum = sum + y
print "\n\n\tfonction2: lif = f.read().replace('\\t','\\n').splitlines()\n"
print 'temps minimal =',min(res2)," secondes"
print " temps moyen =",sum/REPETITIONS," secondes"
titi = Timer('fonction3()', 'from __main__ import fonction3')
res3 = titi.repeat(REPETITIONS,ITERATIONS)
sum = 0
for y in res3:
sum = sum + y
print "\n\n\tfonction3: boucle for et append()\n"
print 'temps minimal =',min(res3)," secondes"
print " temps moyen =",sum/REPETITIONS," secondes" |
Partager