博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Clock
阅读量:4135 次
发布时间:2019-05-25

本文共 861 字,大约阅读时间需要 2 分钟。

计算程序执行所需的时间:

clock_t clock( void );

clock_t start,finish;

#include 
#include
#include
void sleep( clock_t wait );void main( void ){ long i = 600000L; clock_t start, finish; double duration; /* Delay for a specified time. */ printf( "Delay for three seconds\n" ); sleep( (clock_t)3 * CLOCKS_PER_SEC ); printf( "Done!\n" ); /* Measure the duration of an event. */ printf( "Time to do %ld empty loops is ", i ); start = clock(); while( i-- ) ; finish = clock(); duration = (double)(finish - start) / CLOCKS_PER_SEC; printf( "%2.1f seconds\n", duration );}/* Pauses for a specified number of milliseconds. */void sleep( clock_t wait ){ clock_t goal; goal = wait + clock(); while( goal > clock() ) ;}
输出结果为:

Delay for three secondsDone!Time to do 600000 empty loops is 0.1 seconds

转载地址:http://vbsvi.baihongyu.com/

你可能感兴趣的文章
性能扩展问题要趁早
查看>>
PlentyOfFish 网站架构学习
查看>>
Tomcat集群与负载均衡
查看>>
多服务器的用户身份认证方案
查看>>
Tomcat 的集群和负载均衡
查看>>
Lucene构建index性能调整
查看>>
Map Reduce - the Free Lunch is not over?
查看>>
众说纷“云”:看云计算在存储领域异军突起
查看>>
Using Nutch 0.8.1 for Intranet Crawling and Searching
查看>>
类似Google构架的开源项目Hadoop近获社区关注
查看>>
hadoop 分布式文件系统:体系和设计
查看>>
用Hadoop搭建分布式存储和分布式运算集群
查看>>
IBM推动MapReduce发布Eclipse插件
查看>>
Linux 内核剖析
查看>>
使用 Linux 系统调用的内核命令
查看>>
Yahoo!社区架构
查看>>
Tailrank 网站架构
查看>>
Web缓存加速指南
查看>>
WikiPedia 技术架构学习分享
查看>>
Digg 网站架构
查看>>