[前][次][番号順一覧][スレッド一覧]

ruby-changes:51690

From: k0kubun <ko1@a...>
Date: Mon, 9 Jul 2018 02:49:01 +0900 (JST)
Subject: [ruby-changes:51690] k0kubun:r63902 (trunk): benchmark/driver.rb: drop legacy Ruby script support

k0kubun	2018-07-09 02:48:58 +0900 (Mon, 09 Jul 2018)

  New Revision: 63902

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=63902

  Log:
    benchmark/driver.rb: drop legacy Ruby script support
    
    Now all benchmarks are converted to YAMLs.
    
    common.mk: Drop obsoleted bm_* pattern

  Modified files:
    trunk/benchmark/driver.rb
    trunk/common.mk
Index: common.mk
===================================================================
--- common.mk	(revision 63901)
+++ common.mk	(revision 63902)
@@ -1123,7 +1123,7 @@ benchmark: miniruby$(EXEEXT) update-benc https://github.com/ruby/ruby/blob/trunk/common.mk#L1123
 	$(BASERUBY) $(srcdir)/benchmark/driver.rb \
 	            --executables="compare-ruby::$(COMPARE_RUBY) -I$(EXTOUT)/common --disable-gem" \
 	            --executables="built-ruby::$(MINIRUBY) -r$(srcdir)/prelude --disable-gem" \
-	            --pattern='bm_' --directory=$(srcdir)/benchmark $(OPTS)
+	            --directory=$(srcdir)/benchmark $(OPTS)
 
 benchmark-each: miniruby$(EXEEXT) update-benchmark-driver PHONY
 	$(BASERUBY) $(srcdir)/benchmark/driver.rb \
Index: benchmark/driver.rb
===================================================================
--- benchmark/driver.rb	(revision 63901)
+++ benchmark/driver.rb	(revision 63902)
@@ -11,7 +11,6 @@ rescue LoadError https://github.com/ruby/ruby/blob/trunk/benchmark/driver.rb#L11
 end
 
 require 'shellwords'
-require 'tempfile'
 
 class BenchmarkDriver
   # Run benchmark-driver prepared by `make update-benchmark-driver`
@@ -23,69 +22,27 @@ class BenchmarkDriver https://github.com/ruby/ruby/blob/trunk/benchmark/driver.rb#L22
     end
   end
 
-  def initialize(dir, opt = {})
-    @dir = dir
-    @pattern = opt[:pattern] || nil
-    @exclude = opt[:exclude] || nil
-  end
-
-  def with_yamls(&block)
-    ios = files.map do |file|
-      Tempfile.open.tap do |io|
-        if file.end_with?('.yml')
-          io.write(File.read(file))
-        else
-          io.write(build_yaml(file))
-        end
-        io.close
-      end
-    end
-    block.call(ios.map(&:path))
-  ensure
-    ios.each(&:close)
-  end
-
-  private
-
-  def build_yaml(file)
-    magic_comment = '# prelude' # bm_so_nsieve_bits hangs without magic comment
-    name = File.basename(file).sub(/\Abm_/, '').sub(/\.rb\z/, '')
-    script = File.read(file).sub(/^__END__\n(.+\n)*/m, '').sub(/\A(^#[^\n]+\n)+/m) do |comment|
-      magic_comment = comment
-      ''
-    end
-
-    <<-YAML
-prelude: |
-#{magic_comment.gsub(/^/, '  ')}
-benchmark:
-  #{name}: |
-#{script.gsub(/^/, '    ')}
-loop_count: 1
-    YAML
+  def initialize(opt = {})
+    @dir = opt[:dir]
+    @pattern = opt[:pattern]
+    @exclude = opt[:exclude]
   end
 
   def files
-    flag = {}
-    legacy_files = Dir.glob(File.join(@dir, 'bm*.rb'))
-    yaml_files = Dir.glob(File.join(@dir, '*.yml'))
-    files = (legacy_files + yaml_files).map{|file|
+    Dir.glob(File.join(@dir, '*.yml')).map{|file|
       next if @pattern && /#{@pattern}/ !~ File.basename(file)
       next if @exclude && /#{@exclude}/ =~ File.basename(file)
       file
-    }.compact
-
-    files.sort!
-    files
+    }.compact.sort
   end
 end
 
 if __FILE__ == $0
   opt = {
-    :execs => [],
-    :dir => File.dirname(__FILE__),
-    :repeat => 1,
-    :verbose => 1,
+    execs: [],
+    dir: File.dirname(__FILE__),
+    repeat: 1,
+    verbose: 1,
   }
 
   parser = OptionParser.new{|o|
@@ -123,7 +80,6 @@ if __FILE__ == $0 https://github.com/ruby/ruby/blob/trunk/benchmark/driver.rb#L80
   parser.parse!(ARGV)
 
   execs = opt[:execs].map { |exec| ['--executables', exec.shellsplit.join(',')] }.flatten
-  BenchmarkDriver.new(opt[:dir], opt).with_yamls do |yamls|
-    BenchmarkDriver.run(*yamls, *execs, "--verbose=#{opt[:verbose]}", "--repeat-count=#{opt[:repeat]}")
-  end
+  yamls = BenchmarkDriver.new(opt).files
+  BenchmarkDriver.run(*yamls, *execs, "--verbose=#{opt[:verbose]}", "--repeat-count=#{opt[:repeat]}")
 end

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]