-
-
Save simrit1/780c486fe50842f4d353754dd1ab9e55 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 | |
| import ray | |
| iterations_count = round(1e7) | |
| @ray.remote | |
| 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] | |
| @ray.remote | |
| 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): | |
| ray.get([operation.remote(i) for i in input]) | |
| ray.init() | |
| input = range(10) | |
| print('Without NumPy') | |
| run_complex_operations(complex_operation, input) | |
| print('NumPy') | |
| run_complex_operations(complex_operation_numpy, input) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment