bmbm(width = 0) {|job| ...} in Ruby

By: Jeya Emailed: 1704 times Printed: 2282 times    

Latest comments
By: rohit kumar - how this program is work
By: Kirti - Hi..thx for the hadoop in
By: Spijker - I have altered the code a
By: ali mohammed - why we use the java in ne
By: ali mohammed - why we use the java in ne
By: mizhelle - when I exported the data
By: raul - no output as well, i'm ge
By: Rajesh - thanx very much...
By: Suindu De - Suppose we are executing

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, there’s only so much that bmbm can do, and the results are not guaranteed to be isolated from garbage collection and other effects.

Because bmbm takes two passes through the tests, it can calculate the required label width.

      require 'benchmark'

      array = (1..1000000).map { rand }

      Benchmark.bmbm do |x|
        x.report("sort!") { array.dup.sort! }
        x.report("sort")  { array.dup.sort  }
      end

Generates:

       Rehearsal -----------------------------------------
       sort!  11.928000   0.010000  11.938000 ( 12.756000)
       sort   13.048000   0.020000  13.068000 ( 13.857000)
       ------------------------------- total: 25.006000sec

                   user     system      total        real
       sort!  12.959000   0.010000  12.969000 ( 13.793000)
       sort   12.007000   0.000000  12.007000 ( 12.791000)

bmbm yields a Benchmark::Job object and returns an array of Benchmark::Tms objects.


Ruby Home | All Ruby Tutorials | Latest Ruby Tutorials

Sponsored Links

If this tutorial doesn't answer your question, or you have a specific question, just ask an expert here. Post your question to get a direct answer.



Bookmark and Share

Comments(0)


Be the first one to add a comment

Your name (required):


Your email(required, will not be shown to the public):


Your sites URL (optional):


Your comments:



More Tutorials by Jeya
FTP using Ruby
Security in dRuby
Using remote objects under dRuby
bmbm(width = 0) {|job| ...} in Ruby
bm(label_width = 0, *labels) {|report| ...} in Ruby
benchmark(caption = "", label_width = nil, fmtstr = nil, *labels) {|report| ...} in Ruby

More Tutorials in Ruby
Standard Library Packages in Ruby
Module Abbrev in Ruby
encoding and decoding in Ruby using Base64 Module
Benchmark module in Ruby
benchmark(caption = "", label_width = nil, fmtstr = nil, *labels) {|report| ...} in Ruby
bm(label_width = 0, *labels) {|report| ...} in Ruby
bmbm(width = 0) {|job| ...} in Ruby
CGI class in Ruby
URL encode a string in Ruby
escapeElement() in Ruby
escapeHTML() in Ruby
new(type = "query") in Ruby
parse(query) in Ruby
pretty() in Ruby
Format a Time object as a String in Ruby

More Latest News
Most Viewed Articles (in Ruby )
Open and manipulate CSV files in Ruby
Methods in Ruby on rails
unless in Ruby on rails
bmbm(width = 0) {|job| ...} in Ruby
new(type = "query") in Ruby
URL decode a string in Ruby
SimpleDelegator in Ruby
POST a form in Ruby
Using Proxy to connect to URLs in Ruby
IMAP in Ruby
Using Generator in Ruby
Getting started with Ruby on rails
Prompts, Command Lines, Prompts, and irb in Ruby on rails
Naming conventions in Ruby on rails
Command-line Arguments in Ruby on rails
Most Emailed Articles (in Ruby)
Using GServer in Ruby
URL encode a string in Ruby
Module Abbrev in Ruby
encoding and decoding in Ruby using Base64 Module
URL decode a string in Ruby
Reading emails using POP3 in Ruby
Getting started with Ruby on rails
Command-line Arguments in Ruby on rails
Methods in Ruby on rails
unless in Ruby on rails
The Question Mark Operator in Ruby on rails
Standard Library Packages in Ruby
Benchmark module in Ruby
benchmark(caption = "", label_width = nil, fmtstr = nil, *labels) {|report| ...} in Ruby
bm(label_width = 0, *labels) {|report| ...} in Ruby