Created
October 14, 2019 05:31
-
-
Save firejox/6400e2d40aff03fe4ed66f329e5466c8 to your computer and use it in GitHub Desktop.
Channel select unwait benchmark
This file contains hidden or 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