Created
October 14, 2019 05:31
Star
You must be signed in to star a gist
Channel select unwait benchmark
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
ch1 = Channel(Int32).new | |
ch2 = Channel(Int32).new | |
500.times do | |
spawn do | |
r = Random.new | |
ch2.send(r.next_int) | |
end | |
end | |
spawn do | |
loop do | |
ch1.receive | |
end | |
end | |
total_delay = Time::Span::ZERO | |
(ARGV[0]? || 1000).to_i.times do | |
total_delay += Time.measure do | |
select | |
when ch1.send 1 | |
when ch2.send 2 | |
end | |
end | |
end | |
puts total_delay |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment