new

new(execs, dir, opt = {}) Class Public methods

benchmark

benchmark(opt) Class Public methods

realtime

realtime() Class Public methods Returns the elapsed real time used to execute the given block.

measure

measure(label = "") Class Public methods Returns the time used to execute the given block as a Benchmark::Tms object.

bmbm

bmbm(width = 0) Class Public methods Sometimes benchmark results are skewed because code executed earlier encounters different garbage collection overheads than that run later. bmbm attempts to minimize this effect by running the tests twice, the first time as a rehearsal in order to get the runtime environment stable, the second time for real. GC.start is executed before the start of each of the real timings; the cost of this is not included in the timings. In reality, though, the

bm

bm(label_width = 0, *labels) Class Public methods A simple interface to the benchmark method, bm is generates sequential reports with labels. The parameters have the same meaning as for benchmark. require 'benchmark' n = 50000 Benchmark.bm(7) do |x| x.report("for:") { for i in 1..n; a = "1"; end } x.report("times:") { n.times do ; a = "1"; end } x.report("upto:") { 1.upto(n) do ; a = "1"; end } end Generates: user system total real for:

benchmark

benchmark(caption = "", label_width = nil, format = nil, *labels) Class Public methods Invokes the block with a Benchmark::Report object, which may be used to collect and report on the results of individual benchmark tests. Reserves label_width leading spaces for labels on each line. Prints caption at the top of the report, and uses format to format each line. Returns an array of Benchmark::Tms objects. If the block returns an array of Benchmark::Tms objects, these will be used to

memberwise

memberwise(op, x) Instance Protected methods Returns a new Tms object obtained by memberwise operation op of the individual times for this Tms object with those of the other Tms object. op can be a mathematical operation such as +, -, *, /

to_s

to_s() Instance Public methods Same as format.

to_a

to_a() Instance Public methods Returns a new 6-element array, consisting of the label, user CPU time, system CPU time, children's user CPU time, children's system CPU time and elapsed real time.