CC++中的算法速度测试仪

CC++中的算法速度测试仪,第1张

概述我必须以毫秒为单位计算算法速度.在C/C++中,我该怎么做?我需要在输入之前和输出之后写smth但是究竟是什么? 您可以使用< time.h>中的clock()函数. clock()显示自程序启动以来已经过了多少个刻度.宏CLOCKS_PER_SEC包含每秒的滴答数,因此您实际上可以获得时间. //We start measuring here. Remember what was the am 我必须以毫秒为单位计算算法的速度.在C/C++中,我该怎么做?我需要在输入之前和输出之后写smth但是究竟是什么?解决方法 您可以使用< time.h>中的clock()函数.
clock()显示自程序启动以来已经过了多少个刻度.宏CLOCKS_PER_SEC包含每秒的滴答数,因此您实际上可以获得时间.

//We start measuring here. Remember what was the amount of ticks in the //beginning of the part of code you want to test:int start = clock();//<...>//Do your stuff here//<...>int end = clock();//Now check what amount of ticks we have Now. //To get the time,just subtract start from end,and divIDe by CLOCKS_PER_SEC.std::cout << "it took " << end - start << "ticks,or " << ((float)end - start)/CLOCKS_PER_SEC << "seconds." << std::endl;
总结

以上是内存溢出为你收集整理的C/C++中的算法速度测试仪全部内容,希望文章能够帮你解决C/C++中的算法速度测试仪所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1219685.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-05
下一篇 2022-06-05

发表评论

登录后才能评论

评论列表(0条)

保存