Skip to content

Instantly share code, notes, and snippets.

@SirEdvin
Created February 16, 2020 11:56
Show Gist options
  • Save SirEdvin/6f8397471433301a99af98165f5443c3 to your computer and use it in GitHub Desktop.
Save SirEdvin/6f8397471433301a99af98165f5443c3 to your computer and use it in GitHub Desktop.
50.909597396850586
52.03043818473816
import time
import threading
import timeit
def fib(n):
if n == 1 or n == 0:
return 1
return fib(n - 1) + fib(n - 2)
def verycomplexfunc():
for i in range(0, 15):
if i % 2 == 0:
time.sleep(1)
else:
fib(33)
def sequence_call():
start_time = time.time()
verycomplexfunc()
verycomplexfunc()
verycomplexfunc()
end_time = time.time()
return end_time - start_time
def threaded_call():
start_time = time.time()
t1 = threading.Thread(target=verycomplexfunc)
t2 = threading.Thread(target=verycomplexfunc)
t3 = threading.Thread(target=verycomplexfunc)
t1.start()
t2.start()
t3.start()
t1.join()
t2.join()
t3.join()
end_time = time.time()
return end_time - start_time
print(sequence_call())
print(threaded_call())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment