Program running time :)

Hello I use code::block ide with mingw compiler and when I run my program it shows me how much time has passed since i was running my program (execution time: whatever); I want to know how to do that. I tried:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream.h>
#include <time.h>
using namespace std;


int main()
{
    clock_t t1,t2;
    t1=clock();
    //code goes here
    t2=clock();
    float diff ((float)t2-(float)t1);
    cout<<diff<<endl;
    system ("pause");
    return 0;
    
}

but it just shows me in numbers which can't be the real running time. Can please someone help me? The reason I want to know this is in school we started using the dev-c++ ide which is also with mingw compiler but I guess the configuration is different and I might need that in the feature. Knowledge is power :P . Thanks for your help.
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream.h>
#include <time.h>
using namespace std;


int main()
{
    clock_t t1,t2;
    t1=clock();
    //code goes here
    t2=clock();
    float diff ((float)t2-(float)t1);
    cout<<diff<<endl;
    system ("pause");
    return 0;
    
}
R0mai thanks and sorry for the mistake I already have it on my code I edited my post before when I saw the mistake but I don't know why it didn't change. The reason I didn't had t2=clock(); in my prev code is I deleted the code which was between t1 and t2 and I accidently have deleted the t2=clock(); too and then pasted the code. Well as I said the results are the same and I really hope someone can help me. Thanks,.
clock() returns the number of clock ticks since the program was launched
(http://www.cplusplus.com/reference/clibrary/ctime/clock/)

if you want to convert that to seconds, just divide that by the macro CLOCKS_PER_SEC.
 
float seconds = diff / CLOCKS_PER_SEC;
thanks a lot yadude1e3 :)
Topic archived. No new replies allowed.