分类: C/C++
2009-10-25 14:07:56
//:count_time.h
#ifndef _COUNT_TIME_H
#define _COUNT_TIME_H
#include
#include
#include
#include
#include
#include
class TCountTime
{
public:
TCountTime(){}
~TCountTime(){}
public:
void vBegin()
{
gettimeofday(&m_tBegin,0);
}
void vEnd()
{
gettimeofday(&m_tEnd,0);
}
int iCountUsec()
{
return (m_tEnd.tv_sec - m_tBegin.tv_sec)*1000000+(m_tEnd.tv_usec -m_tBegin.tv_usec);
}
public:
timeval m_tBegin;
timeval m_tEnd;
};
#endif
//:main.cpp
#include "count_time.h"
#include
using namespace std;
void test()
{
string the_base(1024*1024*10,'X');
for( int i = 0; i < 100; i++)
{
string the_copy = the_base;
}
}
int main()
{
TCountTime CT;
CT.vBegin();
test();
CT.vEnd();
cout << "cost time:" << CT.iCountUsec() << endl;
}