Thread: Nanoseconds

    #1
  1. Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Dec 2004
    Location
    Meriden, Connecticut
    Posts
    1,797
    Rep Power
    154

    Nanoseconds


    According to answers.com a nanosecond is:
    Code:
    One billionth (10**-9) of a second.
    Don't mis-read the exponential within the code tags. Anyways, I'm working with C++ FILETIME structures however I need to use a likelyness of them in Python. There is a certain function which I must create that uses C++ functions such as GetLocalTime() and GetSystemTime(). I've got these functions writen in Python already, since they are easy. The problem is that I cannot convert both of these values into FILETIME structures. Note: It wouldn't be called "structure" in Python. According to MSDN a FILETIME is a 64-bit value representing the number of 100-nanosecond intervals since January 1, 1601 (UTC). My main concern is retrieving the value of a nanosecond in Python. I'm not sure if it is even possible. If it is not, I will attempt to find a way around this, if it is possible, please show me how to do it or give me an idea. Any help is appreciated.

    Edit: Somewhat solved.
    I used 10**-9 for a nanosecond. I completely forgot about Python having access to exponential values.
    Last edited by †Yegg†; August 22nd, 2005 at 05:17 PM.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Posts
    394
    Rep Power
    51
    Hi!

    Just one quick note: instead of 10**-9 use 1e-9, that's the way to write exponentials in Python

    Regards, mawe
  4. #3
  5. Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Dec 2004
    Location
    Meriden, Connecticut
    Posts
    1,797
    Rep Power
    154
    Well, I guess it is. But it still returns the same value.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Posts
    394
    Rep Power
    51
    I know that it returns the same value, but IMO 10**-9 looks ugly (and is probably slower, I'm not sure).
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2004
    Location
    London, England
    Posts
    1,585
    Rep Power
    1373
    Originally Posted by mawe
    I know that it returns the same value, but IMO 10**-9 looks ugly (and is probably slower, I'm not sure).
    Yes it is:
    Code:
    $ python -m timeit '10**-9'
    1000000 loops, best of 3: 1.75 usec per loop
    
    $ python -m timeit '1e-9'
    10000000 loops, best of 3: 0.136 usec per loop
    
    $ python -m timeit '1'
    10000000 loops, best of 3: 0.133 usec per loop
    10**-9 will calculate the value every time it is encountered, while 1e-9 will be calculated once at compile time - from the above timings, you can see that 1e-9 takes the same time to evaluate as 1.

    Dave - The Developers' Coach

    Comments on this post

    • Grim Archon agrees : The 1e-9 format is the convention for small numbers.
  10. #6
  11. Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Dec 2004
    Location
    Meriden, Connecticut
    Posts
    1,797
    Rep Power
    154
    I guess you guys are right. I'll use 1e-9 instead. Thanks.

IMN logo majestic logo threadwatch logo seochat tools logo