计时:
c++:
// 方法1 (遇到在unity交互是计时出现问题)
#include <time.h> // 计时模块
time_t start,end; // 计时
start=clock();
...
end=clock();
std::cout<<"time: "<<(end-start)/CLOCKS_PER_SEC<<" ms"<<std::endl;
// 方法2
#include <sys/time.h>
timeval start,end;
gettimeofday(&start,0);
...
gettimeofday(&end,0);
double timeuse = 1000000*(end.tv_sec - start.tv_sec) + end.tv_usec - start.tv_usec;
timeuse /=1000;//除以1000则进行毫秒计时,如果除以1000000则进行秒级别计时,如果除以1则进行微妙级别计时
std::cout<<"Linux DBSCAN time: "<<timeuse<<" ms"<<std::endl; // sys/time.h仅linux使用
python
import time
start = time.time()
end = time.time()
延时:
c++:
#include <unistd.h>
sleep(0.03);
python:
import time
time.sleep(0.01)