ruby-changes:34839
From: hsbt <ko1@a...>
Date: Thu, 24 Jul 2014 04:45:16 +0900 (JST)
Subject: [ruby-changes:34839] hsbt:r46922 (trunk): * lib/benchmark.rb: split executable code into sample directory.
hsbt 2014-07-24 04:45:09 +0900 (Thu, 24 Jul 2014) New Revision: 46922 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=46922 Log: * lib/benchmark.rb: split executable code into sample directory. * sample/benchmark.rb: ditto. Added files: trunk/sample/benchmark.rb Modified files: trunk/ChangeLog trunk/lib/benchmark.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 46921) +++ ChangeLog (revision 46922) @@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Thu Jul 24 04:42:13 2014 SHIBATA Hiroshi <shibata.hiroshi@g...> + + * lib/benchmark.rb: split executable code into sample directory. + * sample/benchmark.rb: ditto. + Thu Jul 24 04:36:49 2014 SHIBATA Hiroshi <shibata.hiroshi@g...> * lib/tempfile.rb: split executable code into sample directory. Index: sample/benchmark.rb =================================================================== --- sample/benchmark.rb (revision 0) +++ sample/benchmark.rb (revision 46922) @@ -0,0 +1,19 @@ https://github.com/ruby/ruby/blob/trunk/sample/benchmark.rb#L1 +require 'benchmark' + +include Benchmark + +n = ARGV[0].to_i.nonzero? || 50000 +puts %Q([#{n} times iterations of `a = "1"']) +benchmark(CAPTION, 7, FORMAT) do |x| + x.report("for:") {for _ in 1..n; _ = "1"; end} # Benchmark.measure + x.report("times:") {n.times do ; _ = "1"; end} + x.report("upto:") {1.upto(n) do ; _ = "1"; end} +end + +benchmark do + [ + measure{for _ in 1..n; _ = "1"; end}, # Benchmark.measure + measure{n.times do ; _ = "1"; end}, + measure{1.upto(n) do ; _ = "1"; end} + ] +end Index: lib/benchmark.rb =================================================================== --- lib/benchmark.rb (revision 46921) +++ lib/benchmark.rb (revision 46922) @@ -546,23 +546,3 @@ module Benchmark https://github.com/ruby/ruby/blob/trunk/lib/benchmark.rb#L546 # The default format string used to display times. See also Benchmark::Tms#format. FORMAT = Benchmark::Tms::FORMAT end - -if __FILE__ == $0 - include Benchmark - - n = ARGV[0].to_i.nonzero? || 50000 - puts %Q([#{n} times iterations of `a = "1"']) - benchmark(CAPTION, 7, FORMAT) do |x| - x.report("for:") {for _ in 1..n; _ = "1"; end} # Benchmark.measure - x.report("times:") {n.times do ; _ = "1"; end} - x.report("upto:") {1.upto(n) do ; _ = "1"; end} - end - - benchmark do - [ - measure{for _ in 1..n; _ = "1"; end}, # Benchmark.measure - measure{n.times do ; _ = "1"; end}, - measure{1.upto(n) do ; _ = "1"; end} - ] - end -end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/