Ç - gettimeofday的计算时间呢? [英] C - gettimeofday for computing time?

查看:115
本文介绍了Ç - gettimeofday的计算时间呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你知道如何使用gettimeofday的测量计算时间?我可以通过这个code测量一次:

do you know how to use gettimeofday for measuring computing time? I can measure one time by this code:

  char buffer[30];
  struct timeval tv;

  time_t curtime;



 gettimeofday(&tv, NULL); 
 curtime=tv.tv_sec;

 strftime(buffer,30,"%m-%d-%Y  %T.",localtime(&curtime));
 printf("%s%ld\n",buffer,tv.tv_usec);

这一个计算之前之后进行,第二个。但是,你知道怎么减呢?

This one is made before computing, second one after. But do you know how to subtracts it?

编辑:我需要引起毫秒。和BTW,我为什么不能编辑和创建新的问题发表意见时,看到按钮?

I need result in miliseconds. And BTW, why I can't comment and see buttons when editing and creating new questions?

推荐答案

CURTIME 变量包含从新纪元的秒数​​。如果你得到一前一后,后面的一减较早的企业之一是以秒为单位的经过时间。您可以减去 time_t的值就好了。

Your curtime variable holds the number of seconds since the epoch. If you get one before and one after, the later one minus the earlier one is the elapsed time in seconds. You can subtract time_t values just fine.

这篇关于Ç - gettimeofday的计算时间呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆