Created
March 21, 2023 19:55
-
-
Save jpsamaroo/7da2124ce306ad6ae3e2588368bbdcda 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
using BenchmarkTools | |
function bench_async_yield(N, T) | |
ts = [@async begin | |
for i in 1:N | |
yield() | |
end | |
end for _ in 1:T] | |
wait.(ts) | |
end | |
function bench_spawn_yield(N, T) | |
ts = [Threads.@spawn begin | |
for i in 1:N | |
yield() | |
end | |
end for _ in 1:T] | |
wait.(ts) | |
end | |
function bench_async_create_finish(N) | |
ts = [@async begin | |
end for _ in 1:N] | |
wait.(ts) | |
end | |
function bench_spawn_create_finish(N) | |
ts = [Threads.@spawn begin | |
end for _ in 1:N] | |
wait.(ts) | |
end | |
# 1 thread | |
# Task hooks: | |
# 36.6 ms | |
# Master: | |
# 35.5 ms | |
display(@benchmark bench_async_yield(10_000, 8)) | |
# 3 threads | |
# Task hooks: | |
# 30.33 ms | |
# Master: | |
# 32.71 ms | |
display(@benchmark bench_spawn_yield(10_000, 8)) | |
# 1 thread | |
# Task hooks: | |
# 3.47 ms | |
# Master: | |
# 3.71 ms | |
display(@benchmark bench_async_create_finish(10_000)) | |
# 3 threads | |
# Task hooks: | |
# 4.05 ms | |
# Master: | |
# 3.85 ms | |
display(@benchmark bench_spawn_create_finish(10_000)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment