Skip to content

Instantly share code, notes, and snippets.

@jude90
Created August 29, 2014 01:39
Show Gist options
  • Save jude90/db00d7d94fd57c8c0d9c to your computer and use it in GitHub Desktop.
Save jude90/db00d7d94fd57c8c0d9c to your computer and use it in GitHub Desktop.
thread time
import time
import threading
def deadloop(times):
while times>0:
times -= 1
a = 1 + 2
start = time.time()
deadloop(100000000)
end = time.time()
print "take %f second" %(end-start)
start = time.time()
deadloop(50000000)
end = time.time()
print "take %f second" %(end-start)
t1 = threading.Thread(target= deadloop,args=(100000000,))
t2 = threading.Thread(target= deadloop,args=(50000000,))
t1.start()
t2.start()
start = time.time()
t2.join()
t1.join()
end = time.time()
print "take %f second" %(end-start)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment