单线程
#include<ctime>
int main(int argc, char* argv[]){
clock_t startTime,endTime;
startTime =clock();
your_fun();
endTime = clock();
cout << "run time(ms): " << (endTime - startTime)/1000 << endl;
return 0;
}
多线程
#include<iostream>
#include<thread>
using namespace std;
using namespace std::chrono;
template<class T>
void measure(T&& func) {
auto beg_t = system_clock::now();
func();
auto end_t = system_clock::now();
duration<double> diff = end_t - beg_t;
printf("performTest total time: ");
cout << diff.count()<<endl;
}
void func() {
cout << "This is func thread " << endl;
int s = 0;
for (int i = 0; i < 5; i++)
s += i;
}
int main() {
measure(func);
}