Simple method overhead

Hi all.

I have the method like:
class MyCoolClass
def initialize
@var = []
end

#some other methods push values to @var

#here is method of interest:
def ; @var[idx] end
end

I have those, a bit confusing, profiling results:

Total Self Children Calls Name
0.09 0.05 0.04 66565 MyCoolClass#[]
0.04 0.04 0.00 66565 Array#[]

The strange thing is: method MyCoolClass#[] spends so much time inside
itself, though ALL it do - only call Array#[].
Is this normal? Maybe, because of so huge calls count, but I can’t
understand this :frowning:

Thanks.

V.

On Thursday 26 October 2006 18:31, [email protected] wrote:

#here is method of interest:
itself, though ALL it do - only call Array#[]. Is this normal? Maybe,
because of so huge calls count, but I can’t understand this :frowning:

Thanks.

V.

methods have quite some overhead, so to say :slight_smile:
and this benchmark almost covers your values… so i’d say, yeah - it’s
simply
the overhead

the code

require ‘benchmark’

def one; end
def two; one end
def three; two end

iterate = 66_565

Benchmark.bmbm(20) do |x|
x.report(“one :”) { iterate.times{ one } }
x.report(“two :”) { iterate.times{ two } }
x.report(“three:”) { iterate.times{ three } }
end

=begin result
user system total real
one: 0.080000 0.020000 0.100000 ( 0.090971)
two: 0.080000 0.060000 0.140000 ( 0.134608)
three: 0.190000 0.040000 0.230000 ( 0.325138)
=end