How long did it take to process?

Is it possible to make a consol output of how long time it took for the system to process the code in milliseconds?

Something like:
"This process took 0.001ms to process"


Thanks in advance!
Yes that is possible. Lucky you.
Try this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
//to display amount of time a sequence of code execution
//----------------------header files---------------------------------------------
#include <iostream>
#include <ctime>
//----------------------namespaces---------------------------------------------
using namespace std;
//-------------------------code------------------------------------------

int main()
{
    string mystr;

    clock_t startTime = clock();
    cout<<"How are you? ";
    cin>>mystr;
    cout <<"That took: "<< double( clock() - startTime ) / (double)CLOCKS_PER_SEC<< " seconds." << endl;
    cin.get();
}
A quick way to do it is with GetTickCount(). Just call it twice, once before the code is processed (store that value) then again after the code is processed. Compare the 2 values and that will be a reasonable estimate in milliseconds.
include Windows.h
Last edited on
Thank you Aceix and soranz! =)
Topic archived. No new replies allowed.