Created
September 13, 2024 02:53
-
-
Save tueda/ad0aed286bc0e08fa50c2f3f5a0d5784 to your computer and use it in GitHub Desktop.
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 time | |
import ray | |
delay = 0.01 | |
context = ray.init() | |
num_cpus = ray.available_resources()["CPU"] | |
def busy_wait(duration): | |
time_perf_counter = time.perf_counter | |
start_time = time_perf_counter() | |
while (time_perf_counter() - start_time) < duration: | |
pass | |
@ray.remote | |
def f(): | |
busy_wait(delay) | |
return 1 | |
@ray.remote | |
def g(): | |
return sum(ray.get([f.remote() for _ in range(200)])) | |
print(sum(ray.get([g.remote() for _ in range(500)])) * delay / num_cpus) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment