惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

D
DataBreaches.Net
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
云风的 BLOG
云风的 BLOG
B
Blog
博客园 - Franky
I
InfoQ
A
About on SuperTechFans
博客园_首页
L
LangChain Blog
量子位
腾讯CDC
Microsoft Security Blog
Microsoft Security Blog
博客园 - 【当耐特】
美团技术团队
V
V2EX
Apple Machine Learning Research
Apple Machine Learning Research
雷峰网
雷峰网
MongoDB | Blog
MongoDB | Blog
Microsoft Azure Blog
Microsoft Azure Blog
月光博客
月光博客
T
The Blog of Author Tim Ferriss
P
Proofpoint News Feed
G
Google Developers Blog
Last Week in AI
Last Week in AI

博客园 - Brendan

[转载]Manually configuring Microsoft Internet Information Services (IIS) IIS与TOMCAT协同工作---在IIS下运行JSP页面 AXIS部署错误解决方案集锦 使用System.Web.Mail发送Mail的错误解决方案 类的XML序列化(XML Serialization) [翻译]你可以赚钱,但你不能赚时间 Windows 2003 Server配置IIS服务器(ASP, ASP.NET)全功略 Session state can only be used when enableSessionState is set to true, either in a configuration file or in the Page directive 用MS SQL Server事件探查器来跟踪数据库的操作 反反编译工具——Deploy.NET Buffered I/O 与 Non-Buffered I/O性能差异的实例体验 替换函数(Substitution Function) 主定理(Master Theorem) Dynamic Programming之Longest Increasing Subsequence (LIS)问题 ADO.NET数据库连接模块 ASP.NET控件事件丢失的探究 SQLDMO For C#(翻译) 关联(Association)设计中的扇形陷阱(Fan Traps)和断层陷阱(Chasm Traps) 简单并发控制
C中获取当前时间的函数
Brendan · 2006-04-14 · via 博客园 - Brendan

        突然要用到C程序里调用当前时间,来测试一段代码的运行时间。找了一下是否有可以调用的库函数,没想到真的有:gettimeofday。因为这里的这个应用蛮常用的,所以留个记录在此。

 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 
 4 struct timeval 
 5 
 6     long tv_sec; /* 秒数 */ 
 7     long tv_usec; /* 微秒数 */ 
 8 }; 
 9 
10 struct timezone 
11 
12     int tv_minuteswest; 
13     int tv_dsttime; 
14 }; 
15 
16 int gettimeofday(struct timeval *tv,struct timezone *tz); 
17 
18 void function()
19 {
20    // function to run some time consuming codes
21 }
22 
23 int main(int argc, char *argv[])
24 {
25     struct timeval tpstart,tpend;
26         float timespend; 
27 
28     gettimeofday(&tpstart,NULL); 
29     function();
30     gettimeofday(&tpend,NULL); 
31         timespend = tpend.tv_sec - tpstart.tv_sec;
32         printf("Time Spend: %d", timespend);
33     return EXIT_SUCCESS;
34 }