Speed Race between old and new version 'working with files'
japy.april at gmail.com
japy.april at gmail.com
Fri Oct 27 18:11:46 EDT 2017
import time
avg = float(0)
# copy with WITH function and execute time
for i in range(500):
start = time.clock()
with open('q://my_projects/cricket.mp3', 'rb') as old, open('q://my_projects/new_cricket.mp3', 'wb') as new:
for j in old:
new.write(j)
stop = time.clock()
avg += (stop - start) / 500
print('Execute time with WITH version : ', avg)
# copy with OLD version OPEN FILE function and execute time
for i in range(500):
start = time.clock()
old = open('q://my_projects/cricket.mp3', 'rb')
new = open('q://my_projects/old_cricket.mp3', 'wb')
for j in old:
new.write(j)
old.close()
new.close()
stop = time.clock()
avg += (stop - start) / 500
print('Execute time with OLD version : ', avg)
More information about the Python-list
mailing list