Created
October 14, 2019 06:04
-
-
Save firejox/d1c9c72a68d8092ad5bc31a0e0c74889 to your computer and use it in GitHub Desktop.
Channel close latency
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
total_delay = Time::Span::ZERO | |
done = Channel(Time::Span).new | |
(ARGV[0]? || 1000).to_i.times do |i| | |
ch = Channel(Int32).new | |
501.times do |j| | |
if j == 250 | |
spawn do | |
delay = Time.measure do | |
ch.close | |
end | |
done.send delay | |
end | |
else | |
spawn do | |
delay = Time.measure do | |
ch.receive? | |
end | |
done.send delay | |
end | |
end | |
end | |
501.times do | |
total_delay += done.receive | |
end | |
end | |
puts total_delay |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment