Skip to content

Instantly share code, notes, and snippets.

@mGalarnyk
Created September 1, 2021 20:18
Show Gist options
  • Select an option

  • Save mGalarnyk/b5455b0454815b04363ef9994f22fbf3 to your computer and use it in GitHub Desktop.

Select an option

Save mGalarnyk/b5455b0454815b04363ef9994f22fbf3 to your computer and use it in GitHub Desktop.
import math
import numpy as np
from timebudget import timebudget
from multiprocessing import Pool
iterations_count = round(1e7)
def complex_operation(input_index):
print("Complex operation. Input index: {:2d}".format(input_index))
[math.exp(i) * math.sinh(i) for i in [1] * iterations_count]
@timebudget
def run_complex_operations(operation, input, pool):
pool.map(operation, input)
processes_count = 10
if __name__ == '__main__':
processes_pool = Pool(processes_count)
run_complex_operations(complex_operation, range(10), processes_pool)
@imRajAryan09

Copy link
Copy Markdown

Mine execution decreased 6 times.. This is awesome

@mGalarnyk

Copy link
Copy Markdown
Author

im happy to help!

For everyone else finding this gist, the code above is for a blog comparing different ways to parallelize python: https://towardsdatascience.com/parallelizing-python-code-3eb3c8e5f9cd

@contractmaple

contractmaple commented Jun 30, 2022

Copy link
Copy Markdown

I genuinely value the knowledge you have provided on your blog. I appreciate you sharing this blog foodle

@Timeline12

Copy link
Copy Markdown

I appreciate your post foodle. I've studied several similar topics! I was impressed by your post, unlike others. Please keep creating interesting stuff like these for us and others to read!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment