# Basic millisecond code profile?

**URL:** <https://www.ruby-forum.com/t/basic-millisecond-code-profile/107744>\
**Category:** Ruby\
**Created:** [June 25, 2007, 10:20pm UTC](https://www.ruby-forum.com/t/basic-millisecond-code-profile/107744 "2007-06-25T22:20:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ktheory](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/e480ec/32.png) [@ktheory](https://www.ruby-forum.com/u/ktheory)\
**Post date:** [June 25, 2007, 10:20pm UTC](https://www.ruby-forum.com/t/basic-millisecond-code-profile/107744/1 "2007-06-25T22:20:27Z")

</div>

if I need to see the amount of milliseconds / seconds a method takes can  
I do something like this:

class Person  
attr\_accessor :first  
def pl  
now = Time.now.usec #get milliseconds  
0.upto(10000) do |i|  
i = ‘g’  
end  
now2 = Time.now.usec #get milliseconds  
puts String(now2 - now)  
end  
end  
p = Person.new  
p.pl

whats the best way to do this?

---

<div class="post-metadata">

**Author:** ![ktheory](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/e480ec/32.png) [@ktheory](https://www.ruby-forum.com/u/ktheory)\
**Post date:** [June 25, 2007, 10:20pm UTC](https://www.ruby-forum.com/t/basic-millisecond-code-profile/107744/2 "2007-06-25T22:20:54Z")

</div>

Aaron S. wrote:

> if I need to see the amount of milliseconds / seconds a method takes can  
> I do something like this:
> 
> class Person  
> attr\_accessor :first  
> def pl  
> now = Time.now.usec #get milliseconds  
> 0.upto(10000) do |i|  
> i = ‘g’  
> end  
> now2 = Time.now.usec #get milliseconds  
> puts String(now2 - now)  
> end  
> end  
> p = Person.new  
> p.pl
> 
> whats the best way to do this?

class Person  
attr\_accessor :first  
def pl  
now = Time.now.usec / 1000 #get milliseconds  
0.upto(10000) do |i|  
i = ‘g’  
end  
now2 = Time.now.usec / 1000 #get milliseconds  
puts String(now2 - now)  
end  
end

p = Person.new  
p.pl

whoops, forgot the /1000
