在C / C算法速测仪++ [英] algorithm speed tester in C/C++

查看:76
本文介绍了在C / C算法速测仪++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要我的计算算法的速度毫秒基地。在C ++ / C,我怎么能做到这一点?我需要写输入输出之前和之后的不便,但究竟是什么?

I have to calculate speed of my algorithm in base of milliseconds. In C++/C , how can i do this? I need to write smth before input and after output but what exactly??

推荐答案

您可以使用时钟()函数从< time.h中> 结果
时钟()显示有多少蜱,因为你的程序开始已经过去了。宏 CLOCKS_PER_SEC 包含每秒滴答的数量,这样你就可以真正得到时间。

You could use clock() function from <time.h>
clock() shows how many ticks have passed since your program started. The macro CLOCKS_PER_SEC contains the number of ticks per second, so you can actually get time.

//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算法速测仪++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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