程序运行时间c++/matlab - 鹅要长大

程序运行时间c++/matlab

前言

一般在调试程序的过程中,需要查看代码运行速度的快慢,此时则需要计算代码的运行时间。

实验过程:

c++:

#include<iostream>
#include<time.h>

void do_something()
{
 for(int i=0;i<10000;i++)
  for(int j=0;j<1000;j++)
   ;
}

int main(int arg,char ** argv)
{
 clock_t start = clock();
 do_something();
 clock_t end = clock();
 double time = static_cast<double>(end-start)/CLOCKS_PER_SEC;//单位是秒.
 std::cout << "time = " << time << std::endl;
 return 0;
} 

matlab:

tStart = tic;
do_something();
tElapsed = toc(tStart); %second

做自己该做的事情,做自己喜欢做的事情,安静做一枚有思想的技术媛。