# Check performance with Benchmark

**URL:** <https://www.ruby-forum.com/t/check-performance-with-benchmark/82521>\
**Category:** Ruby\
**Created:** [January 19, 2007, 4:31pm UTC](https://www.ruby-forum.com/t/check-performance-with-benchmark/82521 "2007-01-19T16:31:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![alex-osu3](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/13edae/32.png) [@alex-osu3](https://www.ruby-forum.com/u/alex-osu3)\
**Post date:** [January 19, 2007, 4:31pm UTC](https://www.ruby-forum.com/t/check-performance-with-benchmark/82521/1 "2007-01-19T16:31:05Z")

</div>

Hi all,

I know I can use this format to check the performance  
of my sctipt:

result= Benchmark.measure{##script included here##}

But this code will look ugly if the script spans many  
lines.I wonder 1) if there is a better means and 2)  
what if I want to check the same script for 10000  
times.

Thanks,

Li

---

<div class="post-metadata">

**Author:** ![alex-osu3](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/13edae/32.png) [@alex-osu3](https://www.ruby-forum.com/u/alex-osu3)\
**Post date:** [January 19, 2007, 4:31pm UTC](https://www.ruby-forum.com/t/check-performance-with-benchmark/82521/2 "2007-01-19T16:31:36Z")

</div>

On 1/13/07, chen li [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> times.  
> Hi,

1. you can put the script in a method/function and call that.
2. use 10000.times { } 😉  
either result = Benchmark.measure { 10000.times { script }}  
or result = 1…10000.map { Benchmark.measure { script }}

---

<div class="post-metadata">

**Author:** ![alex-osu3](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/13edae/32.png) [@alex-osu3](https://www.ruby-forum.com/u/alex-osu3)\
**Post date:** [September 25, 2007, 10:35pm UTC](https://www.ruby-forum.com/t/check-performance-with-benchmark/82521/3 "2007-09-25T22:35:10Z")

</div>

— Jan S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi,
> 
> 1. you can put the script in a method/function and  
> call that.
> 2. use 10000.times { } 😉  
> either result = Benchmark.measure { 10000.times {  
> script }}  
> or result = 1…10000.map { Benchmark.measure {  
> script }}

Jan,

Thank you for your cute idea and my script looks  
better now.

Li

---

<div class="post-metadata">

**Author:** ![alex-osu3](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/13edae/32.png) [@alex-osu3](https://www.ruby-forum.com/u/alex-osu3)\
**Post date:** [September 25, 2007, 10:37pm UTC](https://www.ruby-forum.com/t/check-performance-with-benchmark/82521/4 "2007-09-25T22:37:23Z")

</div>

On 13.01.2007 05:03, chen li wrote:

> I know I can use this format to check the performance  
> of my sctipt:
> 
> result= Benchmark.measure{##script included here##}
> 
> But this code will look ugly if the script spans many  
> lines.I wonder 1) if there is a better means and 2)  
> what if I want to check the same script for 10000  
> times.

Just look at the various pieces of sample code using benchmark that are  
posted here (comp.lang.ruby / ruby-talk).

Kind regards

robert
