CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    May 2000
    Location
    Edinburgh, Scotland
    Posts
    3

    How do I time events in applets?

    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?


  2. #2
    Join Date
    Apr 2000
    Location
    Canada
    Posts
    27

    Re: How do I time events in applets?

    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.


  3. #3
    Join Date
    May 2000
    Location
    Edinburgh, Scotland
    Posts
    3

    Re: How do I time events in applets?

    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?



  4. #4
    Join Date
    Apr 2000
    Location
    Canada
    Posts
    27

    Re: How do I time events in applets?

    Could you please be a little more descriptive about your problem?


  5. #5
    Join Date
    May 2000
    Location
    Edinburgh, Scotland
    Posts
    3

    Re: How do I time events in applets?

    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


  6. #6
    Join Date
    Apr 2000
    Location
    Canada
    Posts
    27

    Re: How do I time events in applets?

    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.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured