点云技术相关产学研社区

 找回密码
 立即注册加入PCL中国点云技术相关产学研社区

扫一扫,访问微社区

查看: 2046|回复: 0

C/C++统计算法运行时间代码

[复制链接]
发表于 2013-10-12 01:38:52 | 显示全部楼层 |阅读模式
平常测试个PCL算法的效率,常用代码分享了。
#include < ctime >

time_t tstart, tend;

tstart = time(0);
//your scripts
//
//end
tend = time(0);
cout << “It took ” << difftime(tend, tstart) << ” second(s).” << endl;

It worked fine for me.

Well, if you want to be as precise as possible, then use the following C code, which is at microsecond resolution:

#include <time.h>

double tstart, tstop, ttime;

tstart = (double)clock()/CLOCKS_PER_SEC;

/* YOUR CODES */

tstop = (double)clock()/CLOCKS_PER_SEC;

ttime= tstop-tstart; /*ttime is how long your code run */

回复

使用道具 举报

本版积分规则

QQ|小黑屋|点云技术相关产学研社区 ( 陕ICP备13001629号 )

GMT+8, 2024-5-16 14:06 , Processed in 1.128832 second(s), 16 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表