linux的man页中对gettimeofday函数的说明中,有这样一个说明:
 
$ man gettimeofday
DESCRIPTION
    The functions gettimeofday and settimeofday can get and set the time as
    well as a timezone. The tv argument is a timeval struct, as specified
    in <sys/time.h>:
 
    struct timeval {
          time_t       tv_sec;     /* seconds */
          suseconds_t   tv_usec; /* microseconds */
    };
 
该函数以及Linux内核返回的timeval类型的时间值,tv_usec代表的是微秒精度(10的-6次方秒)。
 
使用举例
#include <stdio.h>
#include <sys/time.h>
#include <time.h> int main(int argc,char * argv[])
{
struct timeval tv;
while(1) {
gettimeofday(&tv,NULL);
printf("time %u:%u\n",tv.tv_sec,tv.tv_usec);
sleep(2);
} return 0;
}

调试一个函数执行时间时,可以使用两个timeval的变量,分别记录函数起始和函数结束时的时间,从而计算出该函数执行的时间消耗。

linux中获取系统时间 gettimeofday函数的更多相关文章

  1. linux中获取系统时间的几种方法

    asctime(将时间和日期以字符串格式表示) 相关函数 time,ctime,gmtime,localtime 表头文件 #include<time.h> 定义函数 char * asc ...

  2. Linux C 获取系统时间信息

    比如获取当前年份:               /* 获取当前系统时间 暂时不使用 ; ; time_t now; struct tm *timenow; time(&now); timeno ...

  3. Linux驱动中获取系统时间

    最近在做VoIP方面的驱动,总共有16个FXS口和FXO口依次初始化,耗用的时间较多.准备将其改为多线程,首先需要确定哪个环节消耗的时间多,这就需要获取系统时间. #include <linux ...

  4. VC++编程中获取系统时间

    <span style="white-space:pre"> </span>总结了在程序中如何获得系统时间的方法 void CGetSystenTimeDl ...

  5. Linux中设置系统时间和时区

    之前公司里有需求要做机器与服务器做时间同步,服务器发送时间戳和时区过来,机器这边根据接收到的时间戳和时区来改时间. 其实很简单,百度上应该也有很多博客有类似的教程,但是这里强调一点,百度上的博客里写的 ...

  6. Java中获取系统时间的四种方式

    第一种: Date day=new Date(); SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss" ...

  7. java总结:Java中获取系统时间(年、月、日)以及下拉菜单默认选择系统年、月、日的方法

    <!-- 获取系统当前的年.月.日 --> <%@ page import="java.util.*"%> <% Calendar calendar= ...

  8. Linux中修改系统时间

    #date //显示当前日期 #date -s //设置当前时间,只有root权限才能设置,其他只能查看. #date -s 20061010 //设置成20061010,这样会把具体时间设置成空00 ...

  9. linux下获取系统时间 和 时间偏移

    获取linux时间  并计算时间偏移 void getSystemTimer(void){#if 0 char *wdate[]={"Sun","Mon",&q ...

随机推荐

  1. Spark 性能相关參数配置具体解释-任务调度篇

    作者:刘旭晖 Raymond 转载请注明出处 Email:colorant at 163.com BLOG:http://blog.csdn.net/colorant/ 随着Spark的逐渐成熟完好, ...

  2. 手动连接数据库(jdbc)

    import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import ...

  3. Fragment-管理Fragment2

    上一篇,给大家讲了有关Fragment管理的几个函数,即add,replace,remove,这节再讲讲其它函数,然后再给大家看一个系统BUG. 一.hide().show() 1.基本使用 这两个函 ...

  4. 【基础篇】点击Button按钮更换图片

    我们在开发的过程中,往往为了美化界面的需要,会修改按钮的默认外观,而因为Android中的按钮有三种状态—默认,被点击,被选中.所以,如果要改变按钮的外观,需要对这三种情况都做出修改,也许在以往,我们 ...

  5. AIX查看HBA卡的WWN号

    1,获得AIX主机连接的光纤设备:        # lsdev -Cc adapter -S a | grep fcs         fcs0      Available 09-08 FC Ad ...

  6. chsh---更换登录系统时使用的shell

    chsh命令   chsh命令用来更换登录系统时使用的shell.若不指定任何参数与用户名称,则chsh会以应答的方式进行设置. 语法 chsh(选项)(参数) 选项 -s<shell 名称&g ...

  7. 今日SGU 5.2

    SGU123 题意:求和 收获:无 #include<bits/stdc++.h> #define de(x) cout<<#x<<"="< ...

  8. 图片上传4-bug修复

    bug1:显示图片的时候,需要判断url是否为空 <#if photo.url != null> <img id="${photo.id}-img" src=&q ...

  9. opencv标定程序(改动)

    转载请注明来自:http://blog.csdn.net/zhouyelihua/article/details/38421377 资源下载见:点击打开链接 百度云盘免积分下载:https://pan ...

  10. Service-监听手机来电

    public class MonitorPhone extends Activity { TelephonyManager tManager; @Override protected void onC ...