Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
require 'digest/sha2'
# GC.disable
N = 1_500_000
#N = 500_000
def workload
sha2 = Digest::SHA2.new
N.times do
# Digest::SHA2.base64digest 'data'.freeze
sha2.reset
sha2 << 'data'.freeze
sha2.base64digest
end
end
# puts 'in the main thread'
# t_start = Time.now
# workload
# puts "Total: %.3f" % (Time.now - t_start)
# puts
worker1 = Ractor.new do
Ractor.receive
print '['; workload; ']'
end
worker2 = Ractor.new do
Ractor.receive
print '['; workload; ']'
end
puts 'in 2 ractors'
t_start = Time.now
worker1.send 'start'
worker2.send 'start'
print '='
print worker1.take
print worker2.take
puts
puts "Total: %.3f" % (Time.now - t_start)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment