2
After some research I have found the solution. It's a library called multiprocessing which seems to be included in python and doing some simple test I was able to see significant performance improvements using it and also got a noticeable increase of CPU usage from 30% to 85-97% on a 4C/8T i5 8250U. Using a perfr counter just running the calculation 4 times took 8.33 seconds, using multiprocessing with 4 processes I got 2.98 seconds which is a significant improvement.
Here's the Python docs if anyone is interested. It provides good examples and explanations. There's also YouTube videos but your mileage may vary.
https://docs.python.org/3/library/multiprocessing.html
This is the software I ran to test the performance
No multiprocessing
import time start=time.perf_counter() def do_something(): x=10 for i in range(22): x=x*x print("Done") do_something() do_something() do_something() do_something() finish=time.perf_counter() print(f"FInished in {round(finish-start, 2)} second(s)")
With multiprocessing
import time import multiprocessing start = time.perf_counter() def do_something(): x=10 for i in range(22): x=x*x print("Done") p1=multiprocessing.Process(target=do_something) p2=multiprocessing.Process(target=do_something) p3=multiprocessing.Process(target=do_something) p4=multiprocessing.Process(target=do_something) if __name__=='__main__': p1.start() p2.start() p3.start() p4.start() p1.join() p2.join() p3.join() p4.join() finish=time.perf_counter() print(f"FInished in {round(finish-start, 2)} second(s)")

Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now