c++中的时间戳

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.

posted @ 2015-09-20 12:34  会孵蛋的鱼  阅读(1695)  评论(0编辑  收藏  举报