Java中有非常易用的时间戳,由于需要在项目中实现C++版本的时间戳,特此记录。
#include <iostream>
#include <stdio.h>
#include <ctime>
int main() {
std::clock_t start;
double duration;
long L=10000000000l;
start = std::clock();
/* Your algorithm here */
while(L--) ; //空语句
duration = ( std::clock() - start ) / (double) CLOCKS_PER_SEC;
std::cout<<"printf: "<< duration <<'\n';
}
注:There is a related constant, CLOCKS_PER_SEC
, which tells you how many clock ticks occur in one second.