dcsimg


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 10 of 10

Thread: High res timers on variable speed cpus...

  1. #1
    Join Date
    Dec 2003
    Posts
    3,366

    High res timers on variable speed cpus...

    Does anyone know of a way to do this yet? I know I can disable the cpu speed changups on some computers, but I forsee a future where this is beyond my control. I also know I can constantly monitor the cpu speed but this introduces a woeful amount of overhead when trying to time something. Other timer methods all seem to be designed for a single frequency as well... I also could tap specific hardware (such as the ram clock speed etc) but I would prefer a portable or general solution if possible.

  2. #2
    Join Date
    Nov 2003
    Posts
    4,118
    What is the resolution you're looking for? I know that some systems have a constant time counter, which cannot be modified by a program or an external command shell. They aren't portable in the sense that you will find them on every platform but they are in C99, in the extended tm struct. Is that what you're after?
    Danny Kalev

  3. #3
    Join Date
    Dec 2003
    Posts
    3,366
    Possibly. Before the new cpu's I was reading the intel time stamp register that is a count of cpu clocks since boot (64 bit int) and dividing by the cpu speed (no longer constant, but the register is still there). I will look at the c99 one, do you think it would work on these systems?

  4. #4
    Join Date
    Dec 2003
    Posts
    3,366
    I was looking for the highest resolution I can get. clock() is worthless, it at least needs to be able to give the run time used by most functions, so around 1/10k-100k second would probably do.

    I tried clock and it cannot time anything that uses less than about 4 million instructions on this new cpu.
    Last edited by jonnin; 02-22-2007 at 11:24 AM.

  5. #5
    Join Date
    Nov 2003
    Posts
    4,118
    gettimeoday is a POSIX extension supported by many other platforms. It has a time resolution of up to a microsecond. Is this what you need?
    Danny Kalev

  6. #6
    Join Date
    Dec 2003
    Posts
    3,366
    possibly, ill give that a look as well. So far everything ive looked at is milisecond or worse. Im still on .net 2002 until we get everything moved to 64 bit then will upgrade to latest... so maybe its a non issue on newer tools.

  7. #7
    Join Date
    Dec 2003
    Posts
    3,366
    This does not appear to exist on my compiler? I searched the help for a while and the only thing that seems to have microsecond res is something that is now obsolete called wbemtime -- which does not appear to work. It always gives all zeros even when asked for the time of day. There are hints that managed c++ might have something, but I am afraid of the managed extensions as we still might have to move off windows at some point. I did not even want to use the wbem one but this section of code is easily replaced (designed to be replaced actually, since it *was* assembly)

    I will keep trying off and on. There are a couple of built in things that look promising but I have not tried them all yet. Fortunately, our embedded side is still fixed cpu speed and likely will be for a year or more, giving us time to resolve the timing issues.

  8. #8
    Join Date
    Dec 2003
    Posts
    3,366
    I found a working function set:
    QueryPerformanceCounter and Frequency worked. Over a 60 second period (sleep function) it came out as expected to approximately 60 seconds. It also was able to time a single (c++) instruction, and does not get "lost" when the cpu changes its speeds.

    First round of growing pains defeated, now to see how to get the most from dual core (now that I can profile the tests properly again..)

  9. #9
    Join Date
    Nov 2003
    Posts
    4,118
    How portable are they? In which headers are they declared?
    Danny Kalev

  10. #10
    Join Date
    Dec 2003
    Posts
    3,366
    Not portable, however they are strongly recommended as the best available for win32 under visual studio. You need windows.h because it uses some *awful* structure/union mess to make 64 bit integers. Its fairly poorly done on that end.
    Wherever the rest of the code resides, it is pulled in by windows.h -- I will see if I can locate its true hiding place when I get back to work.

Similar Threads

  1. GetString Help
    By Chris Yard in forum VB Classic
    Replies: 5
    Last Post: 02-08-2007, 06:44 AM
  2. HIGH SPEED JAVA JTextPane or similar
    By fabioJava in forum Java
    Replies: 1
    Last Post: 07-25-2005, 11:37 PM
  3. Building high speed searching
    By Hariharan in forum .NET
    Replies: 6
    Last Post: 03-22-2005, 01:04 AM
  4. Replies: 37
    Last Post: 10-30-2002, 06:21 AM
  5. Replies: 0
    Last Post: 10-28-2002, 04:22 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
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center