Calculate time of a snippet of a code... c++

How can be time calculated of a snippet or part of a c++ code(execution time of program)? in milliseconds... not dependent on cpu clocks. thnx

1
2
3
4
5
#include <ctime>

clock_t start = clock();
/*Time consuming code*/
std::cout << "Time taken : " << clock() - start << "ms";
Last edited on
#include <time.h>

clock_t start = clock();
/*Time consuming code*/
std::cout << "Time taken : " << ((double)(end-start)/(double)CLOCKS_PER_SEC)<< "s";

This did work for me... gives time in seconds upto 0.00000.
Topic archived. No new replies allowed.