Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

JAVA: Getting the runtime of a program

Options
  • 31-03-2005 4:47pm
    #1
    Closed Accounts Posts: 7


    I'm trying to get the runtime of my program JAVA in order to test how fast different algorithms are running, is there an easy way to get the system time at the beginining of the program and then again at the end?


Comments

  • Registered Users Posts: 4,188 ✭✭✭pH


    When you create a new java.util.Date() it has the current system time in it.

    Date date = new Date();

    You can convert it to millisecs using date.getTime();

    So you get one at the start, one at the end and subtract.


  • Closed Accounts Posts: 7 arcdestroyer


    that worked fine for me, thanks for the help


  • Registered Users Posts: 1,994 ✭✭✭lynchie


    Use this instead. Store teh start and end times, subtract them and it gives you the time it took in milliseconds


  • Registered Users Posts: 21,264 ✭✭✭✭Hobbes


    If you are profiling. Try using a profiler instead.

    http://ejp.sourceforge.net/


Advertisement