# Simple method overhead

**URL:** <https://www.ruby-forum.com/t/simple-method-overhead/73696>\
**Category:** Ruby\
**Created:** [October 26, 2006, 11:31am UTC](https://www.ruby-forum.com/t/simple-method-overhead/73696 "2006-10-26T11:31:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [October 26, 2006, 11:31am UTC](https://www.ruby-forum.com/t/simple-method-overhead/73696/1 "2006-10-26T11:31:46Z")

</div>

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 ☹

Thanks.

V.

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [October 26, 2006, 12:07pm UTC](https://www.ruby-forum.com/t/simple-method-overhead/73696/2 "2006-10-26T12:07:48Z")

</div>

On Thursday 26 October 2006 18:31, removed\_email\_address@domain.invalid 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 ☹
> 
> Thanks.
> 
> V.

methods have quite some overhead, so to say 🙂  
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
