diff options
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | lib/benchmark.rb | 20 | ||||
-rw-r--r-- | sample/benchmark.rb | 19 |
3 files changed, 24 insertions, 20 deletions
@@ -1,3 +1,8 @@ +Thu Jul 24 04:42:13 2014 SHIBATA Hiroshi <[email protected]> + + * lib/benchmark.rb: split executable code into sample directory. + * sample/benchmark.rb: ditto. + Thu Jul 24 04:36:49 2014 SHIBATA Hiroshi <[email protected]> * lib/tempfile.rb: split executable code into sample directory. diff --git a/lib/benchmark.rb b/lib/benchmark.rb index 81ca0bcede..bd3b07284f 100644 --- a/lib/benchmark.rb +++ b/lib/benchmark.rb @@ -546,23 +546,3 @@ module Benchmark # 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 diff --git a/sample/benchmark.rb b/sample/benchmark.rb new file mode 100644 index 0000000000..de5d66f505 --- /dev/null +++ b/sample/benchmark.rb @@ -0,0 +1,19 @@ +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 |