Thursday, October 24, 2013

 

[C++] medir el tiempo transcurrido entre la ejecución de dos líneas de código

          timeval t1, t2;
        double elapsedTime;

        // start timer
        gettimeofday(&t1, NULL);

....       

        // stop timer
        gettimeofday(&t2, NULL);

        // compute and print the elapsed time in millisec
        elapsedTime = (t2.tv_sec - t1.tv_sec) * 1000.0;      // sec to ms
        elapsedTime += (t2.tv_usec - t1.tv_usec) / 1000.0;   // us to ms

Comments: Post a Comment



<< Home

This page is powered by Blogger. Isn't yours?