C++计时的两种方式

    xiaoxiao2022-06-28  162

    #include< ctime >
    using namespace std; clock_t time_start=clock(); //... clock_t time_end=clock(); cout<<"time use:"<<1000*(time_end-time_start)/(double)CLOCKS_PER_SEC<<"ms"<<endl;
    #include< chrono >
    using namespace std; chrono::steady_clock::time_point time_start=chrono::steady_clock::now(); //.... chrono::steady_clock::time_point time_end=chrono::steady_clock::now(); chrono::duration<double> time_used=chrono::duration_cast<chrono::duration<double>>(time_end-time_start); cout<<"time use:"<<time_used.count()<<"s"<<endl;

    最新回复(0)