1 Star 0 Fork 1

saigon/Algorithms

forked from charlieshu/Algorithms 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
纳秒计时.cpp 1.49 KB
一键复制 编辑 原始数据 按行查看 历史
charlie 提交于 2024-01-09 00:01 . move from github to gitee
#include <iostream>
//time(NULL)
#include <time.h>
//gettimeofday(&time, NULL)
#include <sys/time.h>
//std::chrono::steady_clock::now()
#include <chrono>
//usleep();
#include <unistd.h>
//double_t ms
#include <cmath>
//cv::getTickCount()
using namespace std;
int main(){
//ȷ롢΢
cout << "****************************** t5 ******************************"<< endl;
chrono::high_resolution_clock::time_point t51 = chrono::high_resolution_clock::now();
time_t tt51 = std::chrono::high_resolution_clock::to_time_t(t51);
cout << tt51 << " seconds from 1970-01-01 00:00:00 UTC" << std::endl;
sleep(3);
cout << "--------- " << 1000 << " ms ---------- " << 1 << " s ---------" << endl;
chrono::high_resolution_clock::time_point t52 = chrono::high_resolution_clock::now();
time_t tt52 = std::chrono::high_resolution_clock::to_time_t(t52);
cout << tt52 << " seconds from 1970-01-01 00:00:00 UTC" << std::endl;
chrono::nanoseconds t5 = t52 -t51;
cout << "Time elapsed: "<< chrono::duration_cast<chrono::seconds>(t5).count()<< " seconds" << std::endl;
cout << "Time elapsed: "<< chrono::duration_cast<chrono::milliseconds>(t5).count()<< " milliseconds" << std::endl;
cout << "Time elapsed: "<< std::chrono::duration_cast<chrono::microseconds>(t5).count()<< " microseconds" << std::endl;
cout << "Time elapsed: "<< std::chrono::duration_cast<chrono::nanoseconds>(t5).count()<< " nanoseconds" << std::endl;
return 0;
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/saigonshu/algorithm.git
git@gitee.com:saigonshu/algorithm.git
saigonshu
algorithm
Algorithms
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385