# Profiling question

**URL:** <https://www.ruby-forum.com/t/profiling-question/49679>\
**Category:** Ruby\
**Created:** [December 7, 2005, 4:18pm UTC](https://www.ruby-forum.com/t/profiling-question/49679 "2005-12-07T16:18:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![skaes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3be4f8/32.png) [@skaes](https://www.ruby-forum.com/u/skaes)\
**Post date:** [December 7, 2005, 4:18pm UTC](https://www.ruby-forum.com/t/profiling-question/49679/1 "2005-12-07T16:18:15Z")

</div>

During profiling some code using ruby 1.8.2 and standard profiler, I  
have discovered that class method execution time doesn’t get attributed  
to the class where the method is defined. Instead it gets attributed to  
the class of the object issuing the call. This differs from the way  
instance methods are attributed. I’d expect that time gets attributed to  
the defining class instead.

I wonder whether this is by design and expected behavior, or a bug.

To verify this, you can run the following code through the profiler and  
run grep -e ‘foo|bar’ on the result.

==========================================================================================

class Base  
def self.foo  
100.times {|n| n-1}  
end  
def bar  
100.times {|n| n/1}  
end  
end

class A \< Base  
end

class B \< Base  
end

class C \< Base  
def self.foo  
100.times {|n| n+1}  
end  
def bar  
100.times {|n| n\*1}  
end  
end

a = A.new  
b = B.new  
c = C.new

a.class.foo  
b.class.foo  
c.class.foo

# a.bar b.bar c.bar

– stefan

---

<div class="post-metadata">

**Author:** ![skaes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3be4f8/32.png) [@skaes](https://www.ruby-forum.com/u/skaes)\
**Post date:** [December 7, 2005, 4:54pm UTC](https://www.ruby-forum.com/t/profiling-question/49679/2 "2005-12-07T16:54:59Z")

</div>

Hi,

In message “Re: profiling question”  
on Thu, 8 Dec 2005 00:17:28 +0900, Stefan K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
writes:

|During profiling some code using ruby 1.8.2 and standard profiler, I  
|have discovered that class method execution time doesn’t get attributed  
|to the class where the method is defined. Instead it gets attributed to  
|the class of the object issuing the call. This differs from the way  
|instance methods are attributed. I’d expect that time gets attributed to  
|the defining class instead.  
|  
|I wonder whether this is by design and expected behavior, or a bug.

It’s a bug. I have checked in the fix to the CVS repository.  
Thank you.

```
						matz.

```

---

<div class="post-metadata">

**Author:** ![skaes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3be4f8/32.png) [@skaes](https://www.ruby-forum.com/u/skaes)\
**Post date:** [December 7, 2005, 5:07pm UTC](https://www.ruby-forum.com/t/profiling-question/49679/3 "2005-12-07T17:07:12Z")

</div>

Yukihiro M. wrote:

> |the defining class instead.

Wow. That was quick. Thanks very much.

– stefan kaes

[http://railsexpress.de/blog](http://railsexpress.de/blog)
