On Mon, Jun 24, 2013 at 6:59 PM, Andras Horvath <lists / ruby-forum.com>wrote:

> Dear All,
>
> I've spent the last 2 days by trying to find a working memory profiling
> solution for either 1.9.x or 2.0 that can show the memory usage by
> methods.


How exactly do you imagine "memory usage by methods" to be measured?  Are
you just interested in learning how much memory is allocated (temporarily)
from withing a method or do you have a memory leak?


> Similar to the process time output.
>

I usually found "ruby -r profile" helpful.  You can also use module
Benchmark for measuring timing of specific parts of code.  You can even use
Benchmark.measure { ... } around a specific piece and you'll get CPU,
system and wall clock time in an instance of class Benchmark::Tms,


>         # code to profile
>         10000.times { "hello".chars.to_a.shuffle.join }
>

This will allocate objects just temporarily and drop them pretty soon again
=> no leak.  CPU wise on my box:

irb(main):007:0> Benchmark.measure { 10000.times {
"hello".chars.to_a.shuffle.join } }
=>   0.063000   0.000000   0.063000 (  0.066000)

For memory leak detection I once created a small tool with ObjectSpace
which just counts instances per class and outputs deltas.  You might find
it in the archives of this forum.

Kind regards

robert


-- 
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/