Giter Club home page Giter Club logo

bench_press's Introduction

Bench Press

Bench Press is a simple dsl around Ruby's Benchmark library.

Place the code you wish to benchmark inside of a measure block, run the bench_press command and you'll get a markdown report containing your system information and the realtime benchmark.

Additionally, benchmarks can be published to the Ruby Benchmark via bench_press --publish benchmark.rb command.

Creating a new benchmark

Use the --new flag to get started $ bench_press --new benchmark $ vi benchmark.rb

Example

# foo.rb
require 'bench_press'
extend BenchPress

base_string = ""
measure "string append" do
  base_string << "Hello World"
end

base_string = ""
measure "string +=" do
  base_string += "Hello World"
end

$ bench_press foo.rb

Foo
===
Date: August 05, 2010

System Information
------------------
    Operating System:    Mac OS X 10.6.4 (10F569)
    CPU:                 Intel Core 2 Duo 2.4 GHz
    Processor Count:     2
    Memory:              4 GB
    ruby 1.8.7 (2009-12-24 patchlevel 248) [i686-darwin10.2.0], MBARI 0x6770, Ruby Enterprise Edition 2010.01

"string append" is up to 71% faster over 1000 repetitions
---------------------------------------------------------

    string append    0.00270986557006836 secs    Fastest
    string +=        0.00948691368103027 secs    71% Slower

Details

The default number of repetitions is 1000 meaning each measure block is run 1000 times.

Each measure block is run in a forked subprocess in an attempt to isolate the memory usage per measurement. As of 0.3.0, the benchmark is run twice, the first run gets thrown away while the second run is added to the report.

Running the binary/examples locally

I use rubygems but this library is $LOAD_PATH friendly which means we need to set up our own load path when playing locally.

Try sourcing the .dev file

$ source .dev

Note on Patches/Pull Requests

  • Fork the project.
  • Make your feature addition or bug fix.
  • Add tests for it. This is important so I don't break it in a future version unintentionally.
  • Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
  • Send me a pull request. Bonus points for topic branches.

Copyright

Copyright (c) 2009 Sandro Turriate. See LICENSE for details.

bench_press's People

Contributors

groxx avatar rbxbx avatar sandro avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

bench_press's Issues

Cannot publish

I'm on Archlinux with Ruby 1.9.1.
After applying the patch in my fork: http://github.com/manveru/bench_press/commit/e0ff0dbbe752787cef5de6de2157f7f19bd4d578
I get this error when trying to publish.
Haven't digged much further, might be an issue with Facter instead.

/home/manveru/github/manveru/bench_press/lib/bench_press/system_information.rb:34:in `digest': can't convert nil into String (TypeError)
  from /home/manveru/github/manveru/bench_press/lib/bench_press/system_information.rb:34:in `hexdigest'
  from /home/manveru/github/manveru/bench_press/lib/bench_press/system_information.rb:34:in `crypted_identifier'
  from /home/manveru/github/manveru/bench_press/lib/bench_press/report.rb:42:in `to_hash'
  from /home/manveru/github/manveru/bench_press/lib/bench_press/ruby_benchmark.rb:9:in `publish'
  from /home/manveru/github/manveru/bench_press/lib/bench_press/cli.rb:92:in `publish'
  from /home/manveru/github/manveru/bench_press/lib/bench_press/cli.rb:68:in `perform_bench_press'
  from /home/manveru/github/manveru/bench_press/lib/bench_press/cli.rb:55:in `run'
  from /home/manveru/github/manveru/bench_press/bin/bench_press:4:in `<main>'
zsh: exit 1     ~/github/manveru/bench_press/bin/bench_press -p sum.rb

Add benchmark collaboration

This was a great start.

Have you thought of allowing people to submit their benchmark scripts?
And providing a service that records different results?

Maybe store something like:
github or twitter id, date, environment, and result.

Environment could possibly be: machine specs, benchmark, operating system, ruby version, gem version (not sure about this)

Thanks,
Keenan

Error when trying to run test

[13:20:13 miker@optisol-006 ~/optisol/src/rails/benchmarks] $ bench_press --publish tr_vs_gsub.rb
/usr/local/lib/ruby/gems/1.8/gems/bench_press-0.3.0/lib/bench_press/report.rb:59:in heading': undefined methodname' for nil:NilClass (NoMethodError)
from /usr/local/lib/ruby/gems/1.8/gems/bench_press-0.3.0/lib/bench_press/report.rb:63:in runnable_heading' from /usr/local/lib/ruby/gems/1.8/gems/bench_press-0.3.0/lib/bench_press/report.rb:20:into_s'
from /usr/local/lib/ruby/gems/1.8/gems/bench_press-0.3.0/lib/bench_press.rb:95:in puts' from /usr/local/lib/ruby/gems/1.8/gems/bench_press-0.3.0/lib/bench_press.rb:95 from /usr/local/bin/bench_press:19 /usr/local/lib/ruby/gems/1.8/gems/bench_press-0.3.0/lib/bench_press.rb:43:indate': undefined method parse' for Time:Class (NoMethodError) from /usr/local/share/optisol/src/rails/benchmarks/tr_vs_gsub.rb:8 from /usr/local/lib/ruby/gems/1.8/gems/bench_press-0.3.0/lib/bench_press/cli.rb:77:inload'
from /usr/local/lib/ruby/gems/1.8/gems/bench_press-0.3.0/lib/bench_press/cli.rb:77:in measurable' from /usr/local/lib/ruby/gems/1.8/gems/bench_press-0.3.0/lib/bench_press/cli.rb:66:inperform_bench_press'
from /usr/local/lib/ruby/gems/1.8/gems/bench_press-0.3.0/lib/bench_press/cli.rb:55:in run' from /usr/local/lib/ruby/gems/1.8/gems/bench_press-0.3.0/bin/bench_press:4 from /usr/local/bin/bench_press:19:inload'
from /usr/local/bin/bench_press:19

formatted_number broken below 1000

Hi, your current implementation of formatted_number does not work for numbers less than 1000. For example:

formatted_number(999)
=> nil

I see that your implementation borrows heavily from Rails:
http://api.rubyonrails.org/classes/ActionView/Helpers/NumberHelper.html#method-i-number_with_delimiter

The problem? gsub! can return nil if no substitutions are performed:

"Performs the substitutions of String#gsub in place, returning str, or nil if no substitutions were performed."
http://www.ruby-doc.org/core-1.9.3/String.html#method-i-gsub-21

The fix? Change your gsub! to gsub. Gotta love the one character fixes.

Ruby Interp. Should be Identified on main page

I like the web site! Newly found out about it. I think one important metric to skimming benchmarks is what version the interpreter is. I noticed the same test run twice on two different interps getting the opposite result:

Test August 2, 2010
"explicit return" is up to 35% faster over 100000 repetitions
Return August 2, 2010
"implicit return" is up to 12% faster over 100000 repetitions

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.