听人说gettimeofday 在64bit下有缓存,速度很快,测试下了,感觉不对啊。。

#include <time.h>
#include <sys/time.h>
#include <stdio.h>
#include <stdint.h>
int foo(int i)
{
return i;
}
const int64_t MAX_COUNT = *;
struct TimerEval {
TimerEval(const char* module)
{
start_time_ = time(NULL);
module_ = module;
}
~TimerEval()
{
time_t end_time = time(NULL);
printf("%s\telapse : %d sec\n", module_,
(end_time - start_time_));
}
time_t start_time_;
const char* module_;
};
int main()
{
struct timeval tpTmp;
printf("repeat %d times, test result is : \n", MAX_COUNT);
{
TimerEval eval("call fun");
for (int i=; i<MAX_COUNT; ++i)
foo(i);
}
{
TimerEval eval("call time");
for (int i=; i<MAX_COUNT; ++i)
time(NULL);;
}
{
TimerEval eval("call gettimeofday");
for (int i=; i<MAX_COUNT; ++i)
gettimeofday(&tpTmp, NULL);;
}
{
TimerEval eval("call clock_gettime");
struct timespec tp;
for (int i=; i<MAX_COUNT; ++i)
clock_gettime(CLOCK_REALTIME, &tp);
}
return ;
}

测试结果

repeat 100000000 times, test result is :
call fun    elapse : 1 sec
call time    elapse : 1 sec
call gettimeofday    elapse : 7 sec
call clock_gettime    elapse : 15 sec

编译参数

g++ timer_benchmarck.cc -m64 -lrt

貌似事实可能不是这样,求教于大家,可能是什么原因。

如果说time只是在gettimeofday的基础上封装了一层,那怎么time会比gettimeofday还快,不科学啊!

/* Return the current time as a `time_t' and also put it in *T if T is
not NULL. Time is represented as seconds from Jan 1 00:00:00 1970. */
time_t
time (t)
time_t *t;
{
struct timeval tv;
time_t result; if (__gettimeofday (&tv, (struct timezone *) NULL))
result = (time_t) -;
else
result = (time_t) tv.tv_sec;
if (t != NULL)
*t = result;
return result;
}

linux@64 获取时间的性能评估的更多相关文章

  1. linux磁盘I/O的性能评估

    linux磁盘I/O的性能评估 参考自:自学it网,http://www.zixue.it/. (1)使用iostat命令. [test@localhost /]$ iostat -d Linux - ...

  2. Linux c获取时间

    linux c获得时间和设置时间 #include<time.h> //C语言的头文件 #include<stdio.h> //C语言的I/O void main() { ti ...

  3. linux shell获取时间

    获得当天的日期 date +%Y-%m-%d 输出: 2011-07-28 将当前日期赋值给DATE变量DATE=$(date +%Y%m%d) 有时候我们需要使用今天之前或者往后的日期,这时可以使用 ...

  4. Linux date 获取时间

    获取当前日期: ubuser@ubuser-OptiPlex-7010:~$ date +%Y_%m_%d2020_12_16 获取当前时间: ubuser@ubuser-OptiPlex-7010: ...

  5. shell获取时间的相关命令

    Linux shell获取时间和时间间隔(ms级别) 说明:在进行一些性能测试的时候,有时候我们希望能计算一个程序运行的时间,有时候可能会自己写一个shell脚本方便进行一些性能测试的控制(比如希望能 ...

  6. 转贴---Linux服务器性能评估

    http://fuliang.iteye.com/blog/1024360 http://unixhelp.ed.ac.uk/CGI/man-cgi?vmstat ------------------ ...

  7. Linux性能评估命令

    Linux性能评估工具 https://www.cnblogs.com/dianel/p/10085454.html Linux性能评估工具 目录 介绍 负载:uptime 查看内核的信息: dmes ...

  8. Linux服务器性能评估与优化(一)

    网络内容总结(感谢原创) 1.前言简介 一.影响Linux服务器性能的因素   1. 操作系统级         性能调优是找出系统瓶颈并消除这些瓶颈的过程. 很多系统管理员认为性能调优仅仅是调整一下 ...

  9. [转载]Linux服务器性能评估与优化

    转载自:Linux服务器性能评估与优化 一.影响Linux服务器性能的因素 1. 操作系统级 CPU 内存 磁盘I/O带宽 网络I/O带宽 2.        程序应用级 二.系统性能评估标准 影响性 ...

随机推荐

  1. hdu 1559 最大子矩阵 (简单dp)

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=1559 #include <cstring> #include <cstdlib> ...

  2. LA 3704 (矩阵快速幂 循环矩阵) Cellular Automaton

    将这n个格子看做一个向量,每次操作都是一次线性组合,即vn+1 = Avn,所求答案为Akv0 A是一个n*n的矩阵,比如当n=5,d=1的时候: 不难发现,A是个循环矩阵,也就是将某一行所有元素统一 ...

  3. BZOJ 3573 米特运输

    语文题... 原来除了hash还可以取对数啊orz #include<iostream> #include<cstdio> #include<cstring> #i ...

  4. Java [Leetcode 205]Isomorphic Strings

    题目描述: Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the ...

  5. jQuery实战读书笔记(备忘录)

    选择器备忘: | :even 匹配所有索引值为偶数的元素,从 0 开始计数 :odd 匹配所有索引值为奇数的元素,从 0 开始计数 实例——设置table交替行变色: <script type= ...

  6. Discuz!NT静态文件缓存(SQUID)

    在目前最新版本的产品中,我们提供了缓存静态文件的解决方案,就是使用SQUID做静态前端,将论坛中的大部分静态文件布署或外链到一个新的HTTP链接上,其中可以外链的静态文件包括:      1.Disc ...

  7. Nosql释义

    NoSQL不是产品,是一项运动        ---->NoSQL(NoSQL = Not Only SQL ),意即反SQL运动,是一项全新的数据库革命性运动,早期就有人提出,发展至2009年 ...

  8. C# chart控件绘制曲线

    在.NET中以前经常用GDI去绘制,虽然效果也不错,自从.NET 4.0开始,专门为绘制图表而生的Chart控件出现了,有了它,就可以轻松的绘制你所需要的曲线图.柱状图什么的了. using Syst ...

  9. XTUOJ1250 Super Fast Fourier Transform 暴力

    分析:因为加起来不超过1e6,所以最多有1000+个不同的数 做法:离散化搞就好了 #include <cstdio> #include <iostream> #include ...

  10. lightoj 1024 (高精度乘单精度)

    题意:给你一些数,求它们的最小公倍数,结果可能会很大. 统计出每个素因子出现的最大次数,把他们相乘即可,需要高精度. #include<cmath> #include<cstdio& ...