免费教程_免费网赚教程_破解版软件-寂涯网络学习基地

当前位置: 主页 > 系统综合 > 各类编程 > c++时间度量辅助类

c++时间度量辅助类

时间:2011-10-18 23:41来源: 整理:寂涯网络 点击:

 

#ifndef __TIME_MEASURE_H 

#define __TIME_MEASURE_H 

 

#include <sys/time.h> 

 

class time_measure{ 

 public: 

  /**

   * Get the current time

   */ 

  time_measure(); 

 

  /**

   * Calculate the time range(microseconds,i.e.10e-6 second) 

   * and reset the tv_ to current time

   */ 

  long int time_range(); 

 

 private: 

  timeval tv_; 

}; 

 

 

#endif 

 

 

 

#include "time_measure.h" 

 

time_measure::time_measure(){ 

  gettimeofday(&tv_,0); 

 

 

 

long int time_measure::time_range(){ 

  timeval tv; 

  gettimeofday(&tv,0); 

  long int diff = (tv.tv_sec-tv_.tv_sec)*1000000+(tv.tv_usec-tv_.tv_usec); 

  gettimeofday(&tv_,0); 

  return diff; 

 

调用代码很简单:

 

class test{ 

public: 

  void print(){ 

    cout<<"print OK"<<endl; 

  } 

}; 

int main(){ 

  time_measure t; 

  my_application& my_app = my_application_singleton_holder::Instance(); 

  my_app.insert_property("test",shared_ptr<test>(new test)); 

  any a = my_app.get_property("test"); 

  any_cast<shared_ptr<test> >(a)->print(); 

  cout<<"time is:"<<t.time_range()<<" microseconds"<<endl; 

摘自:sheismylife专栏

本页地址 http://www.jybase.net/biancheng/20111018118.html

百度搜索更多

谷歌搜索更多

顶一下
(0)
0%
踩一下
(0)
0%
------分隔线----------------------------

评价:
昵称: 验证码:点击我更换图片
推荐内容
赞助商
赞助商


关于本站免责声明视频更新google百度地图视频地图RRS订阅

如有什么问题请在本站留言,或发邮件到 hxt167#foxmail.com