Click to See Complete Forum and Search --> : How do I time events in applets?


KPrentice
May 3rd, 2000, 09:30 AM
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?

lone_wolf_1985
May 3rd, 2000, 07:46 PM
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.

KPrentice
May 4th, 2000, 04:36 PM
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?

lone_wolf_1985
May 4th, 2000, 06:11 PM
Could you please be a little more descriptive about your problem?

KPrentice
May 5th, 2000, 06:04 AM
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

lone_wolf_1985
May 6th, 2000, 01:14 PM
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.