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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
| from os.path import normpath,getatime,isfile
from os import listdir
from time import strftime,gmtime,clock
sourcePath = normpath(raw_input('\nEntrer le nom du dossier a explorer : ')+'// ')[0:-1]
print
LC,LCstrf,WHILE,WHILEsimpl,FOR = [],[],[],[],[]
for w in xrange(5):
# code eyquem avec temps depuis epoch
te = clock()
fichiers = [ (getatime(sourcePath+fifi),fifi) for fifi in listdir(sourcePath)
if isfile(sourcePath+fifi) ]
fichiers.sort()
tf = clock()
LC.append(tf-te)
if w==0: A = [ v for u,v in fichiers]
# code eyquem avec temps transforme par gmtime et strftime
te = clock()
fichiers = [ (strftime('%Y/%m/%d %H:%M:%S',gmtime(getatime(sourcePath+fifi))),fifi)
for fifi in listdir(sourcePath)
if isfile(sourcePath+fifi) ]
fichiers.sort()
tf = clock()
LCstrf.append(tf-te)
if w==0: B = [ v for u,v in fichiers]
# code de fredm
allfiles,alltimes = [],[]
te = clock()
for fule in listdir(sourcePath):
if isfile(sourcePath +fule):
filetime = getatime(sourcePath + fule)
i = 0
if len(alltimes)==0:
allfiles.append(fule)
alltimes.append(filetime)
else:
while i<len(alltimes) and filetime > alltimes[i]:
i = i + 1
alltimes.insert(i,filetime)
allfiles.insert(i,fule)
tf = clock()
WHILE.append(tf-te)
if w==0: C = allfiles
# code de fredm simplifie
allfiles,alltimes = [],[]
te = clock()
for fule in listdir(sourcePath):
if isfile(sourcePath +fule):
filetime = getatime(sourcePath + fule)
j = 0
while j<len(alltimes) and filetime > alltimes[j]:
j = j + 1
alltimes.insert(j,filetime)
allfiles.insert(j,fule)
tf = clock()
WHILEsimpl.append(tf-te)
if w==0: D = allfiles
# code de fredm transforme en iteration for
allfiles,alltimes = [],[]
te = clock()
k = 0
for fule in listdir(sourcePath):
if isfile(sourcePath +fule):
filetime = getatime(sourcePath + fule)
for k in xrange(len(alltimes)):
if filetime < alltimes[k]: break
elif k==len(alltimes)-1: k+=1
alltimes.insert(k,filetime)
allfiles.insert(k,fule)
tf = clock()
FOR.append(tf-te)
if w==0: E = allfiles
bool ={0:'False',1:'True'}
for x,X in (('B',B),('C',C),('D',D),('E',E)):
print 'A=='+x+' est ' + bool[A==X]
A.sort()
B.sort()
C.sort()
D.sort()
E.sort()
print 'sorted(A)==sorted(B)==sorted(C)==sorted(D)==sorted(E) est ' + bool[A==B==C==D==E]
t1,t2,t3,t4,t5 = min(LC),min(LCstrf),min(WHILE),min(WHILEsimpl),min(FOR)
print '\nTaille du dossier examine : '+str(len(A))
print ' 100.0 %\t(getatime(Path+fifi),fifi) for fifi in listdir(Path)'
print ' ',round(t2*100/t1,1),"%\t(strftime('%Y..%S',gmtime(getatime(Path+fifi))),fifi) for.."
print ' ',round(t3*100/t1,1),'%\tcode de fredm'
print ' ',round(t4*100/t1,1),'%\tcode de fredm simplifie'
print ' ',round(t5*100/t1,1),'%\tcode de fredm transforme en iteration for' |
Partager