# Using benchmark for wait times

**URL:** <https://www.ruby-forum.com/t/using-benchmark-for-wait-times/125377>\
**Category:** Ruby\
**Created:** [January 8, 2008, 6:02pm UTC](https://www.ruby-forum.com/t/using-benchmark-for-wait-times/125377 "2008-01-08T18:02:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![shinji](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c6cbf5/32.png) [@shinji](https://www.ruby-forum.com/u/shinji)\
**Post date:** [January 8, 2008, 6:02pm UTC](https://www.ruby-forum.com/t/using-benchmark-for-wait-times/125377/1 "2008-01-08T18:02:33Z")

</div>

Iâ€™m trying to use Benchmark, to return the wait time for a search in an  
application, and thought I could fairly neatly wrap up the wait time  
like this:

$logger.log(Benchmark.measure($ie.wait()))

However, when I run this test from my harness, I get the following in  
the console:

LocalJumpError: no block given  
C:/ruby/lib/ruby/1.8/benchmark.rb:293:in `measure' ./Tests/test_audittrail.rb:119 ./Tests/test_audittrail.rb:61:in`each’  
./Tests/test\_audittrail.rb:61  
C:/workspace/CV\_Auto/harness.rb:41:in `load' C:/workspace/CV_Auto/harness.rb:41:in`test\_audittrail’

What confuses me further is that line 61 reads:  
message\_type.each do |link|  
$logger.log("")

which when I diff it against my last version, I can see has not changed.

What Iâ€™d like to know is:

Am I off the mark wrapping the wait in a measure and then logging it?

Why does my each statement now fail?

---

<div class="post-metadata">

**Author:** ![shinji](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c6cbf5/32.png) [@shinji](https://www.ruby-forum.com/u/shinji)\
**Post date:** [January 8, 2008, 6:36pm UTC](https://www.ruby-forum.com/t/using-benchmark-for-wait-times/125377/2 "2008-01-08T18:36:05Z")

</div>

On 08.01.2008 18:02, Max R. wrote:

> ```
> C:/ruby/lib/ruby/1.8/benchmark.rb:293:in `measure'
> 
> ```
> 
> which when I diff it against my last version, I can see has not changed.
> 
> What I’d like to know is:
> 
> Am I off the mark wrapping the wait in a measure and then logging it?
> 
> Why does my each statement now fail?

You are not “wrapping the wait in a measure”. Instead you invoke #wait  
and stuff the result into #measure. Consider this:

robert@fussel ~  
$ ruby -r benchmark -e ‘puts Benchmark.measure( sleep(1) )’  
/usr/lib/ruby/1.8/benchmark.rb:293:in `measure’: no block given  
(LocalJumpError)  
from -e:1

robert@fussel ~  
$ ruby -r benchmark -e ‘puts Benchmark.measure{ sleep(1) }’  
0.000000 0.000000 0.000000 ( 1.000000)

Cheers

robert
