Skip to content

Instantly share code, notes, and snippets.

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