Skip to content

Instantly share code, notes, and snippets.

@lopopolo
Created July 9, 2019 09:42
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 lopopolo/6399adfcb4fad5b2fadc6607ada0c665 to your computer and use it in GitHub Desktop.
Save lopopolo/6399adfcb4fad5b2fadc6607ada0c665 to your computer and use it in GitHub Desktop.
Testing GIL throughput on CRuby
#!/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