ruby-changes:65232
From: Takashi <ko1@a...>
Date: Thu, 11 Feb 2021 17:26:33 +0900 (JST)
Subject: [ruby-changes:65232] a0216b1acf (master): Do not run File.write while Ractors are running
https://git.ruby-lang.org/ruby.git/commit/?id=a0216b1acf From a0216b1acf375e8b3fb7dbb31bd5711acc76d05e Mon Sep 17 00:00:00 2001 From: Takashi Kokubun <takashikkbn@g...> Date: Thu, 11 Feb 2021 00:25:45 -0800 Subject: Do not run File.write while Ractors are running also make sure all local variables have the __bmdv_ prefix. --- benchmark/lib/benchmark_driver/runner/ractor.rb | 27 ++++++++++++++----------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/benchmark/lib/benchmark_driver/runner/ractor.rb b/benchmark/lib/benchmark_driver/runner/ractor.rb index 15893b4..c730b8e 100644 --- a/benchmark/lib/benchmark_driver/runner/ractor.rb +++ b/benchmark/lib/benchmark_driver/runner/ractor.rb @@ -66,29 +66,32 @@ Warning[:experimental] = false https://github.com/ruby/ruby/blob/trunk/benchmark/lib/benchmark_driver/runner/ractor.rb#L66 #{prelude} if #{loop_count} == 1 - __bmdv_empty_before = 0 - __bmdv_empty_after = 0 + __bmdv_loop_before = 0 + __bmdv_loop_after = 0 else - __bmdv_empty_before = Time.new + __bmdv_loop_before = Time.new #{while_loop('', loop_count, id: 0)} - __bmdv_empty_after = Time.new + __bmdv_loop_after = Time.new end -ractors = [] -<% results.each do |result| %> -ractors << Ractor.new(__bmdv_empty_after - __bmdv_empty_before) { |loop_time| +__bmdv_ractors = [] +<% results.size.times do %> +__bmdv_ractors << Ractor.new(__bmdv_loop_after - __bmdv_loop_before) { |__bmdv_loop_time| __bmdv_time = Time __bmdv_script_before = __bmdv_time.new #{while_loop(script, loop_count, id: 1)} __bmdv_script_after = __bmdv_time.new - File.write( - <%= result.dump %>, - ((__bmdv_script_after - __bmdv_script_before) - loop_time).inspect, - ) + (__bmdv_script_after - __bmdv_script_before) - __bmdv_loop_time } <% end %> -ractors.each(&:take) + +# Wait for all Ractors before executing code to write results +__bmdv_ractors.map!(&:take) + +<% results.each do |result| %> +File.write(<%= result.dump %>, __bmdv_ractors.shift) +<% end %> #{teardown} RUBY -- cgit v1.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/