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)
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to