Skip to content

Instantly share code, notes, and snippets.

@palnabarun
Last active September 4, 2020 10:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save palnabarun/049a8f8b7eb7d7fcc3c84a5f3256aec2 to your computer and use it in GitHub Desktop.
Save palnabarun/049a8f8b7eb7d7fcc3c84a5f3256aec2 to your computer and use it in GitHub Desktop.
Running the function v/s passing a callable. old.py from https://twitter.com/sunishsurendran/status/1301786397544570881
import concurrent
import time
def execute(count):
start_time = time.time()
with concurrent.futures.ProcessPoolExecutor() as executor:
for _ in range(count):
executor.submit(time.sleep, 1)
elapsed_time = end_time - time.time()
return {"concurrent_time": elapsed_time}
execute(4)
# {'concurrent_time': 1.0378141403198242}
import concurrent
import time
def ExecuteCode(count):
start_time = time.time()
with concurrent.futures.ProcessPoolExecutor() as executor:
for _ in range(count):
executor.submit(time.sleep(1))
end_time = time.time()
elspase_time = end_time-start_time
return {"concurrent_time": elspase_time}
ExecuteCode(4)
# {'concurrent_time': 4.040162563323975}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment