Skip to content

Instantly share code, notes, and snippets.

@firejox
Created October 14, 2019 06:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save firejox/d1c9c72a68d8092ad5bc31a0e0c74889 to your computer and use it in GitHub Desktop.
Save firejox/d1c9c72a68d8092ad5bc31a0e0c74889 to your computer and use it in GitHub Desktop.
Channel close latency
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