* lib/benchmark.rb: split executable code into sample directory.
* sample/benchmark.rb: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46922 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
7d8175a2dc
commit
8fded5ba3e
@ -1,3 +1,8 @@
|
|||||||
|
Thu Jul 24 04:42:13 2014 SHIBATA Hiroshi <shibata.hiroshi@gmail.com>
|
||||||
|
|
||||||
|
* lib/benchmark.rb: split executable code into sample directory.
|
||||||
|
* sample/benchmark.rb: ditto.
|
||||||
|
|
||||||
Thu Jul 24 04:36:49 2014 SHIBATA Hiroshi <shibata.hiroshi@gmail.com>
|
Thu Jul 24 04:36:49 2014 SHIBATA Hiroshi <shibata.hiroshi@gmail.com>
|
||||||
|
|
||||||
* lib/tempfile.rb: split executable code into sample directory.
|
* lib/tempfile.rb: split executable code into sample directory.
|
||||||
|
@ -546,23 +546,3 @@ module Benchmark
|
|||||||
# The default format string used to display times. See also Benchmark::Tms#format.
|
# The default format string used to display times. See also Benchmark::Tms#format.
|
||||||
FORMAT = Benchmark::Tms::FORMAT
|
FORMAT = Benchmark::Tms::FORMAT
|
||||||
end
|
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
|
|
||||||
|
19
sample/benchmark.rb
Normal file
19
sample/benchmark.rb
Normal file
@ -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
|
Loading…
x
Reference in New Issue
Block a user