Results 1 to 7 of 7
  1. #1
    rootpi is offline Member
    Join Date
    Dec 2009
    Posts
    6
    Rep Power
    0

    Default System.nanoTime();

    Hey!

    I've got a little question, why do we use long, instead of float or double, when we are using System.nanoTime();?


    Thanks!

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

  3. #3
    rootpi is offline Member
    Join Date
    Dec 2009
    Posts
    6
    Rep Power
    0

    Default

    Quote Originally Posted by Fubarable View Post
    Which is more accurate, long or double?
    long, I guess ;)

    Thanks!

  4. #4
    tim's Avatar
    tim
    tim is offline Senior Member
    Join Date
    Dec 2007
    Posts
    435
    Rep Power
    7

    Default

    Hi Math.sqrt(Math.PI)! ;)

    I'd just like to warn you about nanosecond accuracy measurements when analyzing algorithms, if you intend to do that. If you use millisecond accuracy to measure the runtime of an algorithm over one iteration, you may typically get 0 ms. So, then one would be tempted to use nanosecond accuracy. However, your machine will typically perform system and other processes within this period and interfere. And to isolate this, would be very difficult. Instead, the analyst should run a set of iterations and average the run time in millisecond accuracy. Repeated sets of measurements should be made.

    Just something to keep in mind. ;)
    Tim
    Eyes dwelling into the past are blind to what lies in the future. Step carefully.

  5. #5
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default

    Repeated sets of measurements should be made
    Agreed. In algorithm analysis, we found that java's garbage collection would really screw with numbers. For very short lists, we'd average hundreds or thousands of trials. I found that for monitoring things like sorting algorithms, its easier to simply make the lists bigger (and average fewer trials :D)

  6. #6
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,798
    Rep Power
    7

    Default

    Fargin spambots!

  7. #7
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

Similar Threads

  1. System as a server
    By anilkumar832 in forum Advanced Java
    Replies: 4
    Last Post: 01-25-2009, 03:49 AM
  2. System.exit 0 or 1?
    By antgaudi in forum New To Java
    Replies: 3
    Last Post: 11-13-2008, 06:33 PM
  3. problem with System.nanoTime()
    By Bryan500 in forum New To Java
    Replies: 5
    Last Post: 11-01-2008, 03:39 PM
  4. File System
    By Zosden in forum Advanced Java
    Replies: 3
    Last Post: 07-26-2008, 04:33 AM
  5. system information
    By nitinborge5 in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 09:25 AM

Posting Permissions

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