利用clock(),CLOCKS_PER_SEC 测试函数运行时间
clock()是C/C++中的计时函数,函数返回从“开启这个程序进程”到“程序中调用clock()函数”时之间的CPU时钟计时单元(clock tick)数
CLOCKS_PER_SEC表示一秒钟内CPU运行的时钟周期数(时钟计时单元)
头文件:#include< ctime >
测试排序函数的运行时间
#include<ctime>
#include<iostream>
using std::cout;
using std::endl;
/*测试排序算法运行时间*/
void testSort(void(*sort)(int[], int), int arr[], int