C++
auto start = chrono::system_clock::now();
/* do something */
auto end = chrono::system_clock::now();
chrono::duration<double> diff = end-start;
cout << "Elapsed time: " << diff.count() << " sec.\n";
很现代化的一种写法(个人认为)
C
struct timeval start_time, end_time;
gettimeofday(&start_time, NULL);
/* do something */
gettimeofday(&end_time, NULL);
long long elapsed_time = (end_time.tv_sec - start_time.tv_sec) * 1000000LL + (end_time.tv_usec - start_time.tv_usec);
printf("Elapsed time: %lld ms.\n", elapsed_time);
单位是ms,该模板来源于操作系统实验
标签:end,chrono,tv,模版,计时,C++,start,time From: https://www.cnblogs.com/liu-yc/p/18112460