Tuesday, September 14, 2010

Useful time of the class



Very often, a piece of code we need to calculate the time-consuming operation, we often write:

The first case, to the millisecond.

clock_t start = null, end = null;

double duration = 0;

start = clock ();

/ / Operation statements here

end = clock ();

duration = (double) (end - start) / CLOCK_PER_SEC;

Second case, accurate to seconds.

time_t start = null, end = null;

int duration = 0;

start = time (NULL);

/ / Operation statements here

end = time (NULL);

duration = end - start;

Is the time to code in C + + projects can be reused, we can to package.

The scope of the object to the use of computing time. Of course, these classes can only be used in certain occasions.

class TimeCost

(

public:

TimeCost () (m_cur = time (NULL);

~ TimeCost ()

(

time_t cur = time (NULL);

prinftf ("Time cost is% d s
", Cur - m_cur;

)

private:

time_t m_cur;

)



class TimeCost2

(

public:

TimeCost2 () (m_cur = clock ();)

~ TimeCost2 ()

(

clock_t cur = clock ();

double cost = (double) (cur - m_cur) / CLOCK_PER_SEC;

printf ("Time cost:% f s
", Cost);

)

private:

clock_t m_cur;

)

Of course, the biggest drawback of these two classes is the strict calculation of time depends on the object's lifetime.






Recommended links:



CNNIC proposes to amend the terms of promoting open to individuals, CN domain name registration



free converter mp4 to 3gp



convert m4a to m4r



Best Animation Tools



Clocks And Alarms Storage



Guide to fully EXPERIENCE the still-mail (a) - attachment



Directory Web Development



Mkv Files



VIDEO formats



BenQ Competing Against The Shining 2008 SEPG Conference



Easy to use EDUCATION



"Plant Wars zombie" automatic "fight" means plant



MSN "offline" stability remains a cause of disease remission



JSF To Pass Parameters Via URL



Teaching Domain Quiz



No comments:

Post a Comment