Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: Quick C problem

  1. #1
    New to the CF scene
    Join Date
    Nov 2002
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Quick C problem

    I was wondering how I could access the current time in milliseconds in C? Basically I want to time how long it takes to do a load of functions by comparing the time I started doing them with the time I finished. The time() function is only accurate to seconds, and hence is completely useless to me. I'm compiling my code in Visual Studio.

    Many thanks.

  • #2
    Regular Coder
    Join Date
    Jul 2002
    Location
    Belgium
    Posts
    124
    Thanks
    0
    Thanked 0 Times in 0 Posts
    quick aswer (and I hope it works for you )
    Code:
    #include <time.h>
    
    int main(void)
    {
    float millisec;
    clock_t start, end;
    
    start=clock()
        yourfunction()
    end=clock();
    millisec = ( float )( end - start ) / ( ( float )CLOCKS_PER_SEC / 1000 );
    printf( "milliseconds: %f\n", millisec );
    return 0;
    }

    -maes

  • #3
    New to the CF scene
    Join Date
    Nov 2002
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up

    Yep, that works.

    Thanks maes - you're a lifesaver!


  •  

    Posting Permissions

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