Created
January 5, 2021 21:05
-
-
Save Inversion-des/a9dbde4eacfa859e5bd7cc8fd8a8049f 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 'openssl' | |
require 'base64' | |
$VERBOSE = nil | |
#GC.disable | |
# N = 1_500_000 | |
N = 100 | |
class BaseEncryption | |
def initialize | |
@encryptor = cipher_base.encrypt.tap do |o| | |
@key = o.random_key | |
@iv = o.random_iv | |
end | |
end | |
def cipher_base | |
OpenSSL::Cipher.new 'AES-256-CBC'.freeze | |
end | |
def encrypt(text) | |
@encryptor.reset | |
encrypted_text = @encryptor.update(text) + @encryptor.final | |
Base64.encode64 encrypted_text | |
end | |
end | |
# Data = ('W'*1000).freeze | |
DATA_ARR = N.times.map do |n| | |
(n.to_s * 1000_000).freeze | |
end.freeze | |
def workload | |
encryptor = BaseEncryption.new | |
N.times do |n| | |
# puts \ | |
encryptor.encrypt DATA_ARR[n] | |
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