//this code is writen by c++
#include <iostream>
#include <ctime>
using namespace std;
class timer{
clock_t start;
public:
timer(); //set new time
~timer(); //distory time() and get new time
};
timer::timer()
{
start = clock;
}
timer::~timer()
{
clock_t end;
end=clock();
cout << "Elapsed time:" << (end-start)/CLOCKS_PER_SEC << endl;
}
int main()
{
timer ob;
char c;
ob.timer();
//for()
//cin >> c;
return 0;
}
#include <iostream>
#include <ctime>
using namespace std;
class timer{
clock_t start;
public:
timer(); //set new time
~timer(); //distory time() and get new time
};
timer::timer()
{
start = clock;
}
timer::~timer()
{
clock_t end;
end=clock();
cout << "Elapsed time:" << (end-start)/CLOCKS_PER_SEC << endl;
}
int main()
{
timer ob;
char c;
ob.timer();
//for()
//cin >> c;
return 0;
}
the code above teaches me how to measure time in c++;and also there is another way in c,gettimeofday function.