找到执行时间 [英] to find execution time
问题描述
请告诉我如何在c中找到程序的执行时间。
提前谢谢你,
vishnu
vi ********* ****@yahoo.com (vishnu mahendra)写道:
请告诉我如何在c中找到程序的执行时间。
在程序开始时调用clock();在你的节目结束时拨打时钟()
;减去两个;除以CLOCKS_PER_SEC。可能不是很精确,但很可能,但它和ISO C一样精确。
Richard
>
Richard Bos写道:
vi ** ***********@yahoo.com (vishnu mahendra)写道:
请告诉我如何查找执行时间程序在c。
在程序开始时调用clock();在你的程序结束时调用clock();减去两个;除以CLOCKS_PER_SEC。可能不是很精确,但它与ISO C一样精确。
那是'如果执行时间表示处理器时间。
如果它代表经过时间,则表示经过时间。配方略有不同:b $ b不同:在开始和结束时调用时间(),并将
两个值交给difftime()。
-
Er ********* @ sun.com
在< 3f *************** @ news.nl.net> rl *@hoekstra-uitgeverij.nl (Richard Bos)写道:
vi ** ***********@yahoo.com(vishnu mahendra)写道:
请告诉我如何在c中找到程序的执行时间。
在程序开始时调用clock();在你的程序结束时调用clock();减去两个;除以CLOCKS_PER_SEC。可能不是很精确,但是它与ISO C一样精确。
如果CPU时间不合理,那就相当精确比1
秒短得多,如果你没有把理查德的建议广告litteram并通过一个简单的CLOCKS_PER_SEC划分
。
除以之前将其转换为float或double。
请注意,您可以通过这种方式获得程序使用的CPU时间。如果你需要实时的
,你必须使用time()和difftime(),但
这个方法的通常分辨率是1秒。对于更好的东西,
你需要使用平台特定的功能。
Dan
-
Dan Pop
DESY Zeuthen,RZ集团
电子邮件: Da **** *@ifh.de
cah you please tell me how to find the execution time of a program in c.
thank you in advance,
vishnu
vi*************@yahoo.com (vishnu mahendra) wrote:
cah you please tell me how to find the execution time of a program in c.
Call clock() at the start of your program; call clock() at the end of
your program; subtract the two; divide by CLOCKS_PER_SEC. Not very
precise, probably, but it''s as precise as ISO C gets.
Richard
Richard Bos wrote:
vi*************@yahoo.com (vishnu mahendra) wrote:cah you please tell me how to find the execution time of a program in c.
Call clock() at the start of your program; call clock() at the end of
your program; subtract the two; divide by CLOCKS_PER_SEC. Not very
precise, probably, but it''s as precise as ISO C gets.
That''s if "execution time" means "processor time."
If it instead means "elapsed time," the recipe is slightly
different: call time() at the start and end, and hand the
two values to difftime().
--
Er*********@sun.com
In <3f***************@news.nl.net> rl*@hoekstra-uitgeverij.nl (Richard Bos) writes:
vi*************@yahoo.com (vishnu mahendra) wrote:cah you please tell me how to find the execution time of a program in c.
Call clock() at the start of your program; call clock() at the end of
your program; subtract the two; divide by CLOCKS_PER_SEC. Not very
precise, probably, but it''s as precise as ISO C gets.
It''s reasonably precise if the CPU time is not much shorter than 1
second and if you don''t take Richard''s advice ad litteram and divide
by a plain CLOCKS_PER_SEC. Convert it to float or double before
dividing by it.
Note that you get the CPU time used by the program this way. If you
need the real time instead, you have to use time() and difftime(), but
the usual resolution of this method is 1 second. For something better,
you need to use platform specific functions.
Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
这篇关于找到执行时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!