Skip to content

Instantly share code, notes, and snippets.

@hankliu5
Last active February 13, 2019 03:38
Show Gist options
  • Save hankliu5/acb936982fe727679756bd964e452274 to your computer and use it in GitHub Desktop.
Save hankliu5/acb936982fe727679756bd964e452274 to your computer and use it in GitHub Desktop.
from threading import Thread
import time
def count():
i = 0
for _ in range(50000000):
i += 1
return True
def main():
thread_table = {}
start_time = time.time()
for tid in range(4):
t = Thread(target=count)
t.start()
thread_table[tid] = t
for i in range(4):
thread_table[i].join()
end_time = time.time()
print("Total time: {} secs".format(end_time - start_time))
if __name__ == '__main__':
main()
# Total time: 51.332960844 secs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment