Created
September 1, 2021 20:25
-
-
Save mGalarnyk/703c53bb98aa94d66bb6c49d48ce5c09 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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] | |
def complex_operation_numpy(input_index): | |
print("Complex operation (numpy). Input index: {:2d}".format(input_index)) | |
data = np.ones(iterations_count) | |
np.exp(data) * np.sinh(data) | |
@timebudget | |
def run_complex_operations(operation, input, pool): | |
pool.map(operation, input) | |
processes_count = 10 | |
if __name__ == '__main__': | |
processes_pool = Pool(processes_count) | |
print('Without NumPy') | |
run_complex_operations(complex_operation, range(10), processes_pool) | |
print('\nNumPy') | |
run_complex_operations(complex_operation_numpy, range(10), processes_pool) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment