PDA

View Full Version : How to count file reading-spead in Python?


sofi
2008-12-16, 18:10
Hi!

I want to know how you count the spead of a file in Python?

import time
# Declartiona of varibles
expectedRate = 60
text = 10 * "dfdkfdfkdfkdfkdkfkdfkkdfkdkfjkdfkkdj39048923894892 38498293843809280948903289048203984092809854820984" # =1000 byte= 1kbyte
f_dir = 'V:/Python_ex/fFile.txt'
f_mod = 'w'
sizeOfFile = 100
f = open(f_dir, f_mod) # create a new file
for i in range(0, sizeOfFile): #Write the text 100 times
f.write(text)
f.close()
f_mod = 'r'
f = open(f_dir, f_mod) #
TimeStart = time.time()
f.read()
TimeEnd = time.time()
difr = TimeEnd - TimeStart
rate = sizeOfFile/difr
print difr
print rate
if expectedRate < rate:
print "error"
else:
print "Pass"


How to get the rate only in seconds? it gives me diffrents rate when i change the sizeOfFile. pleas help me, i am new in python.

//Sofi

blittan
2008-12-17, 09:29
if u use endtime - starttime you will end up with the seconds it took

althekiller
2008-12-17, 09:36
You're doing the math right you're just leaving out the fact that your script doesn't have exclusive control over hardware so the transfer speed won't be the same EVERY time.