#include   <iostream>

#include   <ctime>

#include   <ratio>

#include   <chrono>




1、统计程序耗时

const auto Start = std::chrono::steady_clock::now();

const std::chrono::steady_clock::time_point  End = std::chrono::steady_clock::now();

const std::chrono::duration<double, std::milli> diff = End - Start;

std::cout<<"total time:"<<diff.count()<<"ms"<<std::endl;


2、获取当前时间点,并转为毫秒

std::chrono::system_clock::time_point nowt = std::chrono::system_clock::now();

std::chrono::duration<double, std::milli>  dt = nowt.time_since_epoch();

double  ms = dt.count();


3、获取当前时间点作为文件夹或文件命名

    char    buf[256]="";
    struct tm* date_time;
    time_t  now;
    time(&now);
    date_time = localtime(&now);
    strftime(buf, sizeof(buf)/sizeof(buf[0]), "%Y%m%d_%H%M%S", date_time);
    std::string  dt(buf);





标签: none

评论已关闭