Skip to content

Instantly share code, notes, and snippets.

@firejox
Created October 14, 2019 05:31
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save firejox/6400e2d40aff03fe4ed66f329e5466c8 to your computer and use it in GitHub Desktop.
Channel select unwait benchmark
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