basic millisecond code profile?

Discussion in 'Ruby' started by Aaron Smith, Jun 25, 2007.

  1. Aaron Smith

    Aaron Smith Guest

    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/.
    Aaron Smith, Jun 25, 2007
    #1
    1. Advertising

  2. Aaron Smith

    Aaron Smith Guest

    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/.
    Aaron Smith, Jun 25, 2007
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. palmis

    UTC time in millisecond

    palmis, Jan 10, 2006, in forum: Java
    Replies:
    26
    Views:
    24,856
    Roedy Green
    Jan 19, 2006
  2. Macgyver

    millisecond delay in C - linux

    Macgyver, Jan 7, 2004, in forum: C Programming
    Replies:
    8
    Views:
    2,580
    August Derleth
    Jan 7, 2004
  3. Yeounkun, Oh

    How to sleep during millisecond

    Yeounkun, Oh, Dec 9, 2004, in forum: C Programming
    Replies:
    11
    Views:
    2,889
    Richard Bos
    Dec 14, 2004
  4. WeAreBorg

    timer with millisecond precision

    WeAreBorg, Sep 29, 2005, in forum: C Programming
    Replies:
    2
    Views:
    386
    Skarmander
    Sep 29, 2005
  5. Hunter
    Replies:
    7
    Views:
    652
    pedals
    Sep 13, 2011
Loading...

Share This Page