CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: help with timer

  1. #1
    Join Date
    Jul 2011
    Posts
    5

    Question help with timer

    Hello,

    i have the code below:

    Code:
    #include <sys/time.h>
    #include <iostream>
    
    using namespace std;
    
    int main(void){
            struct timeval start, end;
    	long differ;
    
    	gettimeofday(&start, NULL); 	//start time.
    	
    	do_some_work();
    
    	differ = end.tv_usec - start.tv_usec;	//elapsed time.
            cout << "\n\nelapsed time is " << differ;
    
            return 0;
    }
    i would like to ask the differ is in microseconds or milliseconds ?

    Thanks.

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: help with timer

    The short answer is: neither in microseconds nor milliseconds.
    How is the operator -() defined for struct timeval? I guess it is not defined at all!
    So, the result of your subtraction is not defined either!

    Besides, you did not initialized the end variable, so how do you expect to use it?
    Victor Nijegorodov

  3. #3
    Join Date
    Jul 2011
    Posts
    5

    Re: help with timer

    OK, thanks

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured