Skip to content

Instantly share code, notes, and snippets.

@hankliu5
Last active February 13, 2019 03:36
Show Gist options
  • Save hankliu5/1674203a7eb402b01829c684fcd34d77 to your computer and use it in GitHub Desktop.
Save hankliu5/1674203a7eb402b01829c684fcd34d77 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
t.join()
end_time = time.time()
print("Total time: {} secs".format(end_time - start_time))
if __name__ == '__main__':
main()
# Total time: 13.2221679688 secs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment