measuring milli/microseconds in VC6++

Sharky Forums


Results 1 to 7 of 7

Thread: measuring milli/microseconds in VC6++

  1. #1
    Reef Shark
    Join Date
    Feb 2001
    Posts
    261

    Post measuring milli/microseconds in VC6++

    got any ideas how to do it? Cant seem to find a decent function for it... thanks guys

  2. #2
    Reef Shark biosx's Avatar
    Join Date
    Jun 2001
    Location
    Chicago, IL, USA
    Posts
    448

    Post

    Yoshi,

    I am not sure what is in the STL for C++ (I know the stadard library for C), but look around in the time.h header for some things. That is the only place I can think of.

    Let me know if you find anything.

    Good luck

    ------------------
    ## root is the greed of all evil ##
    ## root is the greed of all evil ##

  3. #3
    Reef Shark
    Join Date
    Feb 2001
    Posts
    261

    Post

    alright, thanks bro - ill have a look

  4. #4
    Tiger Shark DeadKen's Avatar
    Join Date
    Oct 2001
    Location
    Seattle
    Posts
    800

    Post

    Originally posted by yoshi273:
    alright, thanks bro - ill have a look
    For milliseconds, look up GetTickCount.

    If you need better, look up QueryPerformanceCounter and QueryPerformanceFrequency.

    I've only needed them once, but they were easy enough to use (though you need to link with some multimedia stuff I think).


    ------------------
    I want an OS, not a hobby...
    I want an OS, not a hobby...

    Theres nothing more pathetic then someone who wears non-matching socks on purpose.

  5. #5
    Hammerhead Shark
    Join Date
    Dec 2001
    Posts
    1,334

    Smile

    Try this:

    #include <time.h>
    ...
    clock_t tv1, tv2; <-create any two variables of type clock_t
    ...
    tv1 = clock(); <- initial time
    ...
    tv2 = clock(); <-final time


    time1=((tv2 - tv1)/(CLOCKS_PER_SEC / (double) 1.0)); <-time1 can be any double or float and it'll hold the difference between tv2 and tv1.

    CLOCK_PER_SEC is a predefined constant in the time header with a value 1000. The code I listed will give you the time down to milliseconds and put it in time1. To get different units of time, change the 1.0 to other units (say 60 for minutes). I hope that helps


    EDIT: I almost forgot, make sure you're running this on a CPU of at least a few hundred MHz. It will work on slower CPUs, but the way it does it, it has a tendency to loose accuracy over a long period of time if the CPU is exceedingly slow (perhaps a 286 or 386 or slower).
    ------------------
    Formerly bobgod007

    [This message has been edited by Ramuman (edited February 07, 2002).]

  6. #6
    Reef Shark
    Join Date
    Feb 2001
    Posts
    261

    Post

    Thank you all

  7. #7
    Tiger Shark DeadKen's Avatar
    Join Date
    Oct 2001
    Location
    Seattle
    Posts
    800

    Post

    Originally posted by Ramuman:
    Try this:

    #include <time.h>
    ...
    clock_t tv1, tv2; <-create any two variables of type clock_t
    ...
    tv1 = clock(); <- initial time
    ...
    tv2 = clock(); <-final time


    time1=((tv2 - tv1)/(CLOCKS_PER_SEC / (double) 1.0)); <-time1 can be any double or float and it'll hold the difference between tv2 and tv1.

    CLOCK_PER_SEC is a predefined constant in the time header with a value 1000. The code I listed will give you the time down to milliseconds and put it in time1. To get different units of time, change the 1.0 to other units (say 60 for minutes). I hope that helps


    EDIT: I almost forgot, make sure you're running this on a CPU of at least a few hundred MHz. It will work on slower CPUs, but the way it does it, it has a tendency to loose accuracy over a long period of time if the CPU is exceedingly slow (perhaps a 286 or 386 or slower).
    This is a sad implementation for Windows. If Microseconds is your goal, I doubt this will get you close. Go with the hi-res times.

    The time.h stuff uses code which probably uses GetClockTicks. Too much overhead for high accuracy timing.




    ------------------
    I want an OS, not a hobby...
    I want an OS, not a hobby...

    Theres nothing more pathetic then someone who wears non-matching socks on purpose.

Posting Permissions

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