-
-
Save ko1/5e8cb732a8d8ecfe49605674c5a01193 to your computer and use it in GitHub Desktop.
Simple tasks on Ractors
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
Warning[:experimental] = false | |
$:.unshift File.join(__dir__, '.bundle/gems/benchmark-0.4.0/lib/') | |
require 'benchmark' | |
RN = ENV['RN'].to_i | |
raise if RN < 1 | |
ON = (2 * 4 * 8 * 16) * 10_000 | |
TN = ON/RN | |
raise({TN:TN, RN:RN, ON:ON}.inspect) if TN * RN != ON | |
type = ENV['T'].to_sym | |
case type | |
when :regexp | |
def task | |
str = 'hello world' | |
TN.times{ | |
/(h)(e)(l)(l)(o)/ =~ str | |
} | |
end | |
when :new | |
def task | |
TN.times{ | |
'' | |
} | |
end | |
when :newary | |
def task | |
a = [] | |
TN.times{ | |
a = [a] | |
} | |
end | |
else | |
raise | |
end | |
Benchmark.bm(10){|x| | |
if RN == 1 | |
x.report("#{type}/#{RN}"){ | |
task | |
} | |
else | |
x.report("#{type}/#{RN}"){ | |
rs = RN.times.map{ | |
Ractor.new do | |
task | |
:finished | |
end | |
} | |
rs.map(&:take) | |
} | |
end | |
} | |
# p result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment