U:RDoc::NormalModule[iI"Benchmark:EF@0o:RDoc::Markup::Document: @parts[o;;[ o:RDoc::Markup::Paragraph;[I"JThe Benchmark module provides methods to measure and report the time ;TI"used to execute Ruby code.;To:RDoc::Markup::BlankLineo:RDoc::Markup::List: @type: BULLET: @items[o:RDoc::Markup::ListItem: @label0;[ o; ;[I"FMeasure the time to construct the string given by the expression ;TI"$"a"*1_000_000_000:;T@o:RDoc::Markup::Verbatim;[I"require 'benchmark' ;TI" ;TI"2puts Benchmark.measure { "a"*1_000_000_000 } ;T: @format0o; ;[I"=On my machine (OSX 10.8.3 on i5 1.7 GHz) this generates:;T@o;;[I"10.350000 0.400000 0.750000 ( 0.835234) ;T;0o; ;[I"FThis report shows the user CPU time, system CPU time, the sum of ;TI"Hthe user and system CPU times, and the elapsed real time. The unit ;TI"of time is seconds.;T@o;;0;[ o; ;[I";Do some experiments sequentially using the #bm method:;T@o;;[ I"require 'benchmark' ;TI" ;TI"n = 5000000 ;TI"Benchmark.bm do |x| ;TI"0 x.report { for i in 1..n; a = "1"; end } ;TI"0 x.report { n.times do ; a = "1"; end } ;TI"0 x.report { 1.upto(n) do ; a = "1"; end } ;TI" end ;T;0o; ;[I"The result:;T@o;;[ I"0 user system total real ;TI"11.010000 0.000000 1.010000 ( 1.014479) ;TI"11.000000 0.000000 1.000000 ( 0.998261) ;TI"10.980000 0.000000 0.980000 ( 0.981335) ;T;0o;;0;[o; ;[I"AContinuing the previous example, put a label in each report:;T@o;;[ I"require 'benchmark' ;TI" ;TI"n = 5000000 ;TI"Benchmark.bm(7) do |x| ;TI": x.report("for:") { for i in 1..n; a = "1"; end } ;TI": x.report("times:") { n.times do ; a = "1"; end } ;TI": x.report("upto:") { 1.upto(n) do ; a = "1"; end } ;TI" end ;T;0o; ;[I"The result:;T@o;;[ I": user system total real ;TI";for: 1.010000 0.000000 1.010000 ( 1.015688) ;TI";times: 1.000000 0.000000 1.000000 ( 1.003611) ;TI";upto: 1.030000 0.000000 1.030000 ( 1.028098) ;T;0o; ; ; ;[o;;0;[ o; ;[ I"FThe times for some benchmarks depend on the order in which items ;TI"?are run. These differences are due to the cost of memory ;TI"Fallocation and garbage collection. To avoid these discrepancies, ;TI"Dthe #bmbm method is provided. For example, to compare ways to ;TI"sort an array of floats:;T@o;;[ I"require 'benchmark' ;TI" ;TI"'array = (1..1000000).map { rand } ;TI" ;TI"Benchmark.bmbm do |x| ;TI"- x.report("sort!") { array.dup.sort! } ;TI"- x.report("sort") { array.dup.sort } ;TI" end ;T;0o; ;[I"The result:;T@o;;[ I"9Rehearsal ----------------------------------------- ;TI"9sort! 1.490000 0.010000 1.500000 ( 1.490520) ;TI"9sort 1.460000 0.000000 1.460000 ( 1.463025) ;TI"9-------------------------------- total: 2.960000sec ;TI" ;TI"8 user system total real ;TI"9sort! 1.460000 0.000000 1.460000 ( 1.460465) ;TI"9sort 1.450000 0.010000 1.460000 ( 1.448327) ;T;0o;;0;[ o; ;[I"EReport statistics of sequential experiments with unique labels, ;TI"!using the #benchmark method:;T@o;;[I"require 'benchmark' ;TI"Jinclude Benchmark # we need the CAPTION and FORMAT constants ;TI" ;TI"n = 5000000 ;TI"HBenchmark.benchmark(CAPTION, 7, FORMAT, ">total:", ">avg:") do |x| ;TI"? tf = x.report("for:") { for i in 1..n; a = "1"; end } ;TI"? tt = x.report("times:") { n.times do ; a = "1"; end } ;TI"? tu = x.report("upto:") { 1.upto(n) do ; a = "1"; end } ;TI" [tf+tt+tu, (tf+tt+tu)/3] ;TI" end ;T;0o; ;[I"The result:;T@o;;[ I"9 user system total real ;TI";for: 0.950000 0.000000 0.950000 ( 0.952039) ;TI";times: 0.980000 0.000000 0.980000 ( 0.984938) ;TI";upto: 0.950000 0.000000 0.950000 ( 0.946787) ;TI";>total: 2.880000 0.000000 2.880000 ( 2.883764) ;TI":>avg: 0.960000 0.000000 0.960000 ( 0.961255);T;0: @fileI"lib/benchmark.rb;T:0@omit_headings_from_table_of_contents_below0;0;0[[U:RDoc::Constant[iI" CAPTION;FI"Benchmark::CAPTION;T00o;;[o; ;[I"AThe default caption string (heading above the output times).;T;@“;0@“@cRDoc::NormalModule0U;[iI" FORMAT;FI"Benchmark::FORMAT;T00o;;[o; ;[I"VThe default format string used to display times. See also Benchmark::Tms#format.;T;@“;0@“@@Ÿ0[[[I" class;T[[: public[ [I"benchmark;FI"lib/benchmark.rb;T[I"bm;F@²[I" bmbm;F@²[I" measure;F@²[I" realtime;F@²[:protected[[: private[[I" instance;T[[;[[;[[;[ [@±@²[@´@²[@¶@²[@¸@²[@º@²[[U:RDoc::Context::Section[i0o;;[;0;0[@“@“cRDoc::TopLevel