網(wǎng)站首頁 編程語言 正文
1、time clock()計(jì)算時(shí)間間隔
#include <time.h> //頭文件
#include <iostream>
int main(){
clock_t t0, t1;
t0 = clock();
//code
t1 = clock();
std::cout<<"時(shí)間間隔: "<< t1 - t0 << " 微秒"<< std::endl;
return 0;
}
注意! 單位是: 微秒。
2、std::chrono計(jì)算時(shí)間間隔
#include <chrono>
#include <iostream>
int main(){
auto t0 = std::chrono::system_clock::now();
//code
auto t1 = std::chrono::system_clock::now();
auto tt = std::chrono::duration_cast<std::chrono::milliseconds>(t1 - t0).count();
std::cout<<"時(shí)間間隔: "<< tt << " 毫秒"<< std::endl;
return 0;
}
單位轉(zhuǎn)化
如果需要其他的時(shí)間刻度,可用下列替換上面代碼duration_cast<std::chrono::milliseconds>
中的std::chrono::milliseconds
。
- std::chrono::hours
- std::chrono::minutes
- std::chrono::seconds
- std::chrono::milliseconds
- std::chrono::microseconds
3、參考
C++獲取時(shí)間間隔
C++11 - std::chrono - 使用std::chrono::duration_cast進(jìn)行時(shí)間轉(zhuǎn)換
原文鏈接:https://blog.csdn.net/Kevin_Xie86/article/details/125857903
相關(guān)推薦
- 2021-12-07 Android證書安裝過程介紹_Android
- 2022-12-02 基于Go語言實(shí)現(xiàn)類似tree命令的小程序_Golang
- 2023-04-01 Android自定義View?Material?Design理念詳解_Android
- 2023-12-13 idea git只查看某個(gè)人提交的代碼記錄
- 2022-07-06 C#數(shù)據(jù)適配器DataAdapter_C#教程
- 2022-07-11 在web頁面播放rtsp流視頻(webrtc)
- 2022-09-17 C/C++?中實(shí)現(xiàn)讓控制臺(tái)暫停的方法_C 語言
- 2024-03-05 git的使用
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運(yùn)行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲(chǔ)小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運(yùn)算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯(cuò)誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實(shí)現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡(jiǎn)單動(dòng)態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對(duì)象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊(duì)列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支