Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > basic millisecond code profile?

Reply
Thread Tools

basic millisecond code profile?

 
 
Aaron Smith
Guest
Posts: n/a
 
      06-25-2007
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?

--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Aaron Smith
Guest
Posts: n/a
 
      06-25-2007
Aaron Smith 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

--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need to implement a calendar clock with millisecond resolution, please help. Hunter C Programming 7 09-12-2011 11:59 PM
UTC time in millisecond palmis Java 26 01-19-2006 07:38 AM
timer with millisecond precision WeAreBorg C Programming 2 09-29-2005 12:27 AM
How to sleep during millisecond Yeounkun, Oh C Programming 11 12-14-2004 02:29 PM
millisecond delay in C - linux Macgyver C Programming 8 01-07-2004 12:28 PM



Advertisments