Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

JAVA: Getting the runtime of a program

  • 31-03-2005 04: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, Registered Users 2 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, Registered Users 2, Paid Member Posts: 2,032 ✭✭✭lynchie


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


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


    If you are profiling. Try using a profiler instead.

    http://ejp.sourceforge.net/


Advertisement