Time C++ in milliseconds

Posted by Vincius Prado da Fonseca on May 13, 2014

A simple example on how to get the time in milliseconds using clock from time.h.

#include <time.h>
#include <iostream>

int main() {
    clock_t time_begin, time_end;
	time_begin = clock();
	// Your code here
	time_end = clock();
	cout << (((float)time_end - (float)time_begin) / (double)CLOCKS_PER_SEC ) * 1000 << endl;
}

Some explanation from documentation:

it merely measures the total CPU time devoted so far to the current process.

=]