Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 when i try to find my run time it is always zero
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
B1u3z




PostPosted: Tue Feb 14, 2012 2:51 pm   Post subject: when i try to find my run time it is always zero

long time ;
time = System.currentTimeMillis();
( rest of program)
time = System.currentTimeMillis() - time ;
JOptionPane.showMessageDialog (null, time+"ms","time", JOptionPane.WARNING_MESSAGE);

i am trying to find my run time of my program but every time i run it states that it took 0ms. can i get some help on ho to fix this
Sponsor
Sponsor
Sponsor
sponsor
Zren




PostPosted: Tue Feb 14, 2012 3:12 pm   Post subject: RE:when i try to find my run time it is always zero

What does the rest of your program do? The code is fine. Your program is probably just not resource intensive enough to have those two sections of code to happen in a different clock cycle.

If you want to confirm this, dump a Thread.sleep in there with it's appropritate exception handling.

Java:


public class Test {
        public static void main(String[] args) {
                long time;
                time = System.currentTimeMillis();
                try {
                        Thread.sleep(1000);
                } catch (InterruptedException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                }
                time = System.currentTimeMillis() - time;
                JOptionPane.showMessageDialog(null, time + "ms", "time", JOptionPane.WARNING_MESSAGE);
        }
}
mirhagk




PostPosted: Tue Feb 14, 2012 11:08 pm   Post subject: RE:when i try to find my run time it is always zero

Your computer runs in gigahertz. That's trillions of operations every second, which is billions every million second. SO unless your code is a billion operations it won't show up.
Insectoid




PostPosted: Wed Feb 15, 2012 7:52 am   Post subject: Re: RE:when i try to find my run time it is always zero

mirhagk @ Tue Feb 14, 2012 11:08 pm wrote:
Your computer runs in gigahertz. That's trillions of operations every second, which is billions every million second. SO unless your code is a billion operations it won't show up.


Quote:
Thread.sleep(1000);
B1u3z




PostPosted: Wed Feb 15, 2012 12:12 pm   Post subject: Re: when i try to find my run time it is always zero

thanks for the help
Insectoid




PostPosted: Wed Feb 15, 2012 12:40 pm   Post subject: RE:when i try to find my run time it is always zero

Oh, my bad. I thought Zren was OP (as I didn't check the username) and only read the title and code snippet.
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 6 Posts ]
Jump to:   


Style:  
Search: