Last active
September 4, 2020 10:10
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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