求某段程序运行的高精度时间

Linux环境下:

/**

struct timeval
{
  time_t tv_sec; // 秒
  suseconds_t tv_usec; // 微妙 (10的负六次方)
};

typedef struct timespec{
 time_t tv_sec;//秒
 long tv_nsex;//纳秒
}timespec_t;

**/

#include <algorithm>
#include <vector>
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
double getTime()

 struct timeval tv; 
 gettimeofday(&tv, NULL); 
 //return tv.tv_sec + tv.tv_usec / 1000000.0;
 return tv.tv_sec + tv.tv_usec;
}
using namespace std;
int main()
{  
 
 vector<int> vec(1024*1024/sizeof(int)); 
 for (int i = 0; i < vec.size(); ++i)   
  vec[i] = lrand48(); 
 printf("sorting %zd elements\n", vec.size()); 
 double sorting = getTime();  
 sort(vec.begin(), vec.end()); 
 double done = getTime(); 
 printf("sort %f micros\n", done - sorting);
 return 0;
}

在windows下统计程序运行高精度时间参见另外一篇文章 “1G 数据在入门双核中运行”。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值