Thread: Cycle counters

  1. #1
    Registered User
    Join Date
    Jul 2007

    Cycle counters

    Does anybody knows of a function or a link where I can find a function that will give me the time in milliseconds for an interval of time...???

    I would really appreciate it,


  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Oregon, USA
    You can use gettimeofday(). Call it once before, and once after the event you're trying to time. Then just take the difference of the times and blamo, you've got it.
    If you understand what you're doing, you're not learning anything.

  3. #3
    Registered User
    Join Date
    Aug 2007
    you can use this one
    here the computer waits for 1000 nano seconds as mentioned in brackets
    what sort of program do u want to do??
    is that a sort of stop watch??

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Farncombe, Surrey, England
    the function "clock" will give you some sort of "fraction of a second" time, it may not be milliseconds, but it's the most portable "short time" function. Include "time.h" and use "CLOCKS_PER_SEC" to figure out what the time is (use float/double to mace it fractions of a second). Also use "clock_t" as the type for the result of the function.

    If that's not precise enough, QueryPerformanceCounter/QueryPerformanceCounterFrequency is a Windows function set that will give you around 1 us or better resolution.

    gettimeofday() on Linux will be pretty good too.

    Or "rdtsc", which is an assembler instruction to read the number of clock-cycles as a 64-bit number in EAX/EDX (assuming x86 processor of course).

    I'd try "clock()" first, then work down the list as/if needed.


Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Multigrid V cycle for PDE solver
    By lagnajita in forum C Programming
    Replies: 0
    Last Post: 03-06-2009, 03:40 AM
  2. life cycle of exception object
    By George2 in forum C++ Programming
    Replies: 43
    Last Post: 02-13-2008, 07:50 AM
  3. [C] Best way to save matrix counters
    By Nazgulled in forum C Programming
    Replies: 7
    Last Post: 03-24-2006, 05:02 PM
  4. Fidning a cycle in a directed graph.
    By apacz in forum C++ Programming
    Replies: 9
    Last Post: 10-31-2005, 04:22 PM
  5. Understanding the Window WinMain Cycle
    By BillBoeBaggins in forum Windows Programming
    Replies: 4
    Last Post: 12-06-2003, 12:49 PM