Created
July 9, 2019 09:42
-
-
Save lopopolo/6399adfcb4fad5b2fadc6607ada0c665 to your computer and use it in GitHub Desktop.
Testing GIL throughput on CRuby
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
#!/usr/bin/env ruby | |
# frozen_string_literal: true | |
# Ruby GIL test | |
# Ideally this should saturate two cores. | |
a = [] | |
b = [] | |
t1 = Thread.new do | |
received = 0 | |
loop do | |
break if received > 500_000_000 | |
b.push(received) | |
unless a.pop.nil? | |
received += 1 | |
puts "a received #{received} messages" if (received % 25_000_000).zero? | |
end | |
end | |
end | |
t2 = Thread.new do | |
received = 0 | |
loop do | |
break if received > 500_000_000 | |
a.push(received) | |
unless b.pop.nil? | |
received += 1 | |
puts "b received #{received} messages" if (received % 25_000_000).zero? | |
end | |
end | |
end | |
t1.join | |
t2.join |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment