How to test USB Drive speed with Python Code
Its amazing to test usb drive speed with python, a small script in python can check the removable disk’s speed. Just run the code in python and you will get your Removable USB Flash Drive(Pen Drive) Speed. Here is how you can test pendrive speed with python.
Code provided in 2nd method can test speed of usb device on all operating systems.
How to test Pen Drive speed with Python
1st Method to Run Speed Test (windows only)
- Plug -in your USB drive to the computer
- Open Python 2.7
- Run the code
Python Code For Quick Speed Test (
[alert style=”grey]
import time, os
path = raw_input("Enter the Path Drive Letter of Removale Drive. e.g I ")
pat= path.split(":")
testFile = path+":/crazyTest"
print "Checking your Removable Drive Speed......"
def test(sTime):
f = open(testFile,'a')
for i in range(0,160000):
f.write('we are testing write speed')
f.close()
diff = time.clock() - sTime
speed = (os.stat(testFile).st_size/1048576)/diff
os.unlink(testFile)
print "your Removable. drive speed is "+ str(100/int(diff)) +"% near above "+str(speed)+" mb/sec"
startTime = time.clock()
test(startTime)
[/alert]
The above code will generate a file in your USB file system. This code is estimating the speed of your usb drive by getting the time difference before it start writing the file and when it is finished.
2nd Method to Run Speed Test (All operating systems)
You can download the above code from github repository: usb-speed-test-python
- Run main.py file
- Type full and correct path
- Result would be an approx drive speed in mb/sec
Thanks for using the script !!