I am currently experimenting with a Python zipfile password cracker, which is multi-threaded. I thought a new thread is like a new connection/instance, basically getting the job done faster, only when i removed threading and timed the differences I am left shocked with the apparent drop in performance (x6 slower). I will insert the code here in case that's the issue.
import zipfile
from threading import Thread
def extractFile(zFile, password):
try:
zFile.extractall(pwd=password)
print '[+] Password:', password
except:
pass
def main():
zFile = zipfile.ZipFile('encrypted.zip')
passFile = open('dictionary.txt', 'r')
for line in passFile.readlines():
password = line.strip('\n')
t = Thread(target=extractFile, args=(zFile,password))
t.start()
if __name__ == '__main__':
main()
Once I remove threading it completes 6 times faster. The time results are:
Threaded
real 18m46.974s
user 18m25.936s
sys 9m6.872s
Non threaded
real 3m32.674s
user 3m6.400s
sys 0m25.664s
Why is this happening? I expected that using a multi-threaded approach would improve performance.