# Perfomance tuning

**URL:** <https://www.ruby-forum.com/t/perfomance-tuning/88657>\
**Category:** Ruby\
**Created:** [March 13, 2007, 11:37am UTC](https://www.ruby-forum.com/t/perfomance-tuning/88657 "2007-03-13T11:37:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![emilsverige](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/77aa72/32.png) [@emilsverige](https://www.ruby-forum.com/u/emilsverige)\
**Post date:** [March 13, 2007, 11:37am UTC](https://www.ruby-forum.com/t/perfomance-tuning/88657/1 "2007-03-13T11:37:16Z")

</div>

Hi,  
I have an application that takes a little to long to execute. I would  
like to know where I could gain most.

Whenever a metod is called, I would like to store the execution time and  
number of executions. Then, at the end of the applications execution,  
print it out. Something like:

Object1 =\>  
method1 =\> called 10 times, 30 milliseconds total time  
method2 =\> called 1 times, 5 milliseconds total time  
Object2 =\>  
method1 =\> called 1 times, 2 milliseconds total time  
method2 =\> called 30 times, 500 milliseconds total time  
…

How would I do this?  
Regards  
Emil

---

<div class="post-metadata">

**Author:** ![emilsverige](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/77aa72/32.png) [@emilsverige](https://www.ruby-forum.com/u/emilsverige)\
**Post date:** [March 13, 2007, 11:47am UTC](https://www.ruby-forum.com/t/perfomance-tuning/88657/2 "2007-03-13T11:47:48Z")

</div>

On 3/13/07, Emil S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi,  
> I have an application that takes a little to long to execute. I would  
> like to know where I could gain most.

The best way is ruby-prof ([http://ruby-prof.rubyforge.org](http://ruby-prof.rubyforge.org)). It will  
generate ascii or html formatted output showing the time spent in  
methods. See  
[http://www.oreillynet.com/ruby/blog/2006/08/profiling\_ruby\_code\_with\_rubyp.html](http://www.oreillynet.com/ruby/blog/2006/08/profiling_ruby_code_with_rubyp.html)  
for links to a series of 3 blog posts describing its use.

Alex

---

<div class="post-metadata">

**Author:** ![emilsverige](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/77aa72/32.png) [@emilsverige](https://www.ruby-forum.com/u/emilsverige)\
**Post date:** [March 13, 2007, 11:49am UTC](https://www.ruby-forum.com/t/perfomance-tuning/88657/3 "2007-03-13T11:49:48Z")

</div>

Emil S. wrote:

> method2 =\> called 1 times, 5 milliseconds total time  
> Object2 =\>  
> method1 =\> called 1 times, 2 milliseconds total time  
> method2 =\> called 30 times, 500 milliseconds total time  
> …
> 
> How would I do this?

Investigate ‘profile’ in the standard library  
([http://www.rubycentral.com/book/trouble.html](http://www.rubycentral.com/book/trouble.html)) or ruby-prof  
([http://ruby-prof.rubyforge.org/](http://ruby-prof.rubyforge.org/)). Both do what you want, but the  
latter is more comprehensive.

---

<div class="post-metadata">

**Author:** ![emilsverige](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/77aa72/32.png) [@emilsverige](https://www.ruby-forum.com/u/emilsverige)\
**Post date:** [March 13, 2007, 11:58am UTC](https://www.ruby-forum.com/t/perfomance-tuning/88657/4 "2007-03-13T11:58:36Z")

</div>

Thank you for your quick replies, I will look into this at once.

/Emil
