time in picosecond precision..

This is a discussion on time in picosecond precision.. within the C Programming forums, part of the General Programming Boards category; in C gettimeofday() function gives time in micro second precision. Similarly is there is any function in c for pico ...

  1. #1
    Registered User
    Join Date
    May 2007
    Posts
    19

    time in picosecond precision..

    in C gettimeofday() function gives time in micro second precision.

    Similarly is there is any function in c for pico or nano second precision..


    pls reply me as soon as possible...

    Thanks in advance

  2. #2
    Technical Lead QuantumPete's Avatar
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    894
    gethrtime() might do what you want, but it doesn't give you the current date and time, it can only be used to measure the *length* of time between two events (such as measuring how long a for loop takes as an example)

    QuantumPete
    "No-one else has reported this problem, you're either crazy or a liar" - Dogbert Technical Support
    "Have you tried turning it off and on again?" - The IT Crowd

  3. #3
    Registered User
    Join Date
    May 2007
    Posts
    19
    Thanks... But any other functions to do same?
    Last edited by msenthil; 08-31-2007 at 01:53 AM.

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,344
    1GHz == 1nS per oscillation (what speed is your machine running at BTW).
    Also, light travels about 30cm in 1nS (in a vacuum).

    What could you possibly be measuring which requires pico second (which is 1000 times faster than nano) precision?

    This is like measuring the speed of a bullet with a sundial!
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Like Salem says, there's no way you can measure something in less than few nanoseconds precision without some extra hardware (and I'm not at all sure you can actually get anything that gets to picoseconds).

    If it's a modern x86 (AMD or Intel) processor, there will be a "timestampcounter" (TSC) register, whcih is a 64-bit register that counts clock-cycles. It is counting at the speed of the processor clock in most systems - more recent processors have or have plans for a constant frequency TSC, where the TSC runs at, say, 2GHz, no matter what speed the processor actually runs at (one of the big problems with TSC is that it varies when the processor is put in slow-frequency mode to save power - PowerNow/Cool'n'Quiet/SpeedStep technologies).

    For short periods of time, the TSC should be fine - there is some latency involved, and it's not a synchronizing instruction in itself - that means that the RDTSC instruction can be executed "out of order", meaning that if you have a sequence that ENDS with RDTSC, there's no guarantee that the whole sequence is finished before the RDTSC is actually performed by the processor.

    --
    Mats

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Representing floats with color?
    By DrSnuggles in forum C++ Programming
    Replies: 113
    Last Post: 12-30-2008, 08:11 AM
  2. time precision (ctime), tm struct question
    By cjschw in forum C++ Programming
    Replies: 1
    Last Post: 12-26-2003, 12:51 PM
  3. calculating user time and time elapsed
    By Neildadon in forum C++ Programming
    Replies: 0
    Last Post: 02-10-2003, 05:00 PM
  4. time class
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 12-11-2001, 09:12 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21