Created
January 5, 2021 20:57
-
-
Save Inversion-des/fcc7dbb2d9a77a7dba540c29077e5ebf to your computer and use it in GitHub Desktop.
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
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