Chinaunix首页 | 论坛 | 博客
  • 博客访问: 24831
  • 博文数量: 7
  • 博客积分: 230
  • 博客等级: 二等列兵
  • 技术积分: 90
  • 用 户 组: 普通用户
  • 注册时间: 2009-08-28 10:47
文章分类
文章存档

2011年(2)

2010年(1)

2009年(4)

我的朋友

分类: 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;
}

 

阅读(494) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~