basic millisecond code profile?

A

Aaron Smith

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?
 
A

Aaron Smith

Aaron said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top