C程序措施的执行时间为一个指令 [英] C Program measure execution time for an instruction

查看:105
本文介绍了C程序措施的执行时间为一个指令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要找到执行一个指令或少数几个指示,并打印出来以毫秒为单位的时间。可有一个人请分享小code片断这一点。

谢谢..我需要使用这一措施所花费的时间在我的项目执行一些指令。


解决方案

 #包括LT&;&time.h中GT;
主要()
{
clock_t表示T1 =时钟();
的printf(虚拟声明\\ n);
clock_t表示T2 =时钟();
输出(所用的时间是..%G,(T2-T1));

请看看下面的链接才可了。
<一href=\"http://stackoverflow.com/questions/1083142/whats-the-correct-way-to-use-printf-to-print-a-clock-t\">What’s正确的方法用printf打印clock_t表示?

http://www.velocityreviews.com/论坛/ t454464-C-GET-时间在milliseconds.html

I need to find the time taken to execute a single instruction or a few couple of instructions and print it out in terms of milli seconds. Can some one please share the small code snippet for this.

Thanks.. I need to use this measure the time taken to execute some instructions in my project.

解决方案

#include<time.h> 
main()
{
clock_t t1=clock();
printf("Dummy Statement\n");
clock_t t2=clock();
printf("The time taken is.. %g ", (t2-t1));

Please look at the below liks too. What’s the correct way to use printf to print a clock_t?

http://www.velocityreviews.com/forums/t454464-c-get-time-in-milliseconds.html

这篇关于C程序措施的执行时间为一个指令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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