Hi,
I was wondering if anybody knows how to time something when you're using an applet. I want to time how long quicksort takes to run on certain lengths of arrays, and then plot my results. Does anyone know how to get real time values?
Printable View
Hi,
I was wondering if anybody knows how to time something when you're using an applet. I want to time how long quicksort takes to run on certain lengths of arrays, and then plot my results. Does anyone know how to get real time values?
Try this.
Create a long integer that will hold the current millisecond since 1970. So assign the return value of the method System.currentTimeMillis() to this long when you are about to begin the quicksort. After the quicksort is performed, write a statement that outputs the number of milliseconds it took.
Here's an example:
long time = System.currentTimeMillis();
//perform the quicksort
System.out.println("The quicksort took " + (System.currentTimeMillis() - time) + " milliseconds.");
Good luck.
Thanks for your reply, but I didn't think it was possible to use System commands in applets. I tried a similar approach and it didn't work. Any advice?
Could you please be a little more descriptive about your problem?
I didn't think you could use System commands in applets because applets don't have access to system resources like that. When I tried the approach you suggested and viewed my applet through appletviewer it worked fine and I got sensible numbers. However when I viewed my applet on line through a browser, all my results were 0. This led me to the conclusion that the System command wasn't working. Do you think this is the right conclusion?
Kathryn
It sounds like the right conclusion to me, but I tried testing System.currentTimeMillis() and it seemed to work just fine. The test I performed was simple, all it did was print out the current time in milliseconds though, but it worked.
Try doing something simpler, so you can isolate the code that actually uses the System class method, for example, printing the time.