# Benchmarking whole programs

**URL:** <https://rubytalk.org/t/benchmarking-whole-programs/17440>\
**Category:** ruby-talk\
**Created:** [5 April 2005 16:34 UTC](https://rubytalk.org/t/benchmarking-whole-programs/17440 "2005-04-05T16:34:45Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![gabriele\_renzi5](https://avatars.discourse-cdn.com/v4/letter/g/e79b87/32.png) [@gabriele\_renzi5](https://rubytalk.org/u/gabriele_renzi5)\
**Post date:** [5 April 2005 16:34 UTC](https://rubytalk.org/t/benchmarking-whole-programs/17440/1 "2005-04-05T16:34:45Z")

</div>

Hi gurus and nubys,

I was playing with the ruby programs in the alioth language shootout  
and I realized I have no idea on how to benchmark them all.  
What I mean is: If I want to benchmark a single function I can use the usual benchmark code also shown in ri, but what if I want to check two slightly different implementations of a a single program?

I can't just stick them all in a #meth1 and #meth2 thing, since there may be constants defined (actually they almost surely will, at least classes and modules), I suppose I could do something like:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[Benchmark.bm](http://Benchmark.bm) do |x|  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x.report {require 'first\_impl'; main()}  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x.report {require 'second\_impl'; main()}  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end

but this seems kludgy and loading the thing at each run could mess up the results, I think.  
Some suggestions, apart from using the time unix utility ?
