C++ 高精度时钟获取当前时间 std::chrono::high_resolution_clock::now

C++ 高精度时钟获取当前时间 std::chrono::high_resolution_clock::now

  • 1. `std::chrono::high_resolution_clock::now`
    • 1.1. Parameters
    • 1.2. Return value
    • 1.3. Example
  • 2. `std::chrono::milliseconds`
  • 3. `std::chrono::microseconds`
    • 3.1. Example
  • References

1. std::chrono::high_resolution_clock::now

Get current time
https://cplusplus.com/reference/chrono/high_resolution_clock/now/

// public static member function
static time_point now() noexcept;

Returns the current time_point in the frame of the high_resolution_clock.

1.1. Parameters

none

1.2. Return value

The time_point representing the current time.

time_point is a member type, defined as an alias of time_point<high_resolution_clock>.

1.3. Example

#include <iostream>
#include <ctime>
#include <ratio>
#include <chrono>int main() {using namespace std::chrono;high_resolution_clock::time_point begin = high_resolution_clock::now();std::cout << "Printing out 1000 stars...\n";for (int i = 0; i < 1000; ++i) { std::cout << "*"; }std::cout << std::endl;high_resolution_clock::time_point end = high_resolution_clock::now();duration<double> time_span = duration_cast<duration<double>>(end - begin);std::cout << "It took me " << time_span.count() << " seconds.";std::cout << std::endl;return 0;
}

在这里插入图片描述

Printing out 1000 stars...
****************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************
It took me 0.0411305 seconds.
请按任意键继续. . .

time_point is a member type, defined as an alias of time_point<high_resolution_clock>.

#include <iostream>
#include <ctime>
#include <ratio>
#include <chrono>int main() {using namespace std::chrono;time_point<high_resolution_clock> begin = high_resolution_clock::now();std::cout << "Printing out 1000 stars...\n";for (int i = 0; i < 1000; ++i) { std::cout << "*"; }std::cout << std::endl;time_point<high_resolution_clock> end = high_resolution_clock::now();duration<double> time_span = duration_cast<duration<double>>(end - begin);std::cout << "It took me " << time_span.count() << " seconds.";std::cout << std::endl;return 0;
}
Printing out 1000 stars...
****************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************
It took me 0.033101 seconds.
请按任意键继续. . .

2. std::chrono::milliseconds

Duration in milliseconds

// class
typedef duration < /* see rep below */, milli > milliseconds;

Instantiation of duration to represent milliseconds.

A millisecond (from milli- and second; symbol: ms) is a unit of time in the International System of Units equal to one thousandth (0.001 or 1 0 − 3 10^{-3} 103 or 1/1000) of a second or 1000 microseconds.

1 millisecond (1 ms)

3. std::chrono::microseconds

Duration in microseconds

// class
typedef duration < /* see rep below */, micro > microseconds;

Instantiation of duration to represent microseconds.

A microsecond is a unit of time in the International System of Units (SI) equal to one millionth (0.000001 or 1 0 − 6 10^{-6} 106 or 1/1,000,000) of a second. Its symbol is μs, sometimes simplified to us when Unicode is not available.

1 microsecond (1 μs)

3.1. Example

#include <iostream>
#include <ctime>
#include <ratio>
#include <chrono>int main() {std::chrono::time_point<std::chrono::high_resolution_clock> begin = std::chrono::high_resolution_clock::now();std::cout << "Printing out 1000 stars...\n";for (int i = 0; i < 1000; ++i) { std::cout << "*"; }std::cout << std::endl;std::chrono::time_point<std::chrono::high_resolution_clock> end = std::chrono::high_resolution_clock::now();std::chrono::milliseconds time_span_ms = std::chrono::duration_cast<std::chrono::milliseconds>(end - begin);std::chrono::microseconds time_span_us = std::chrono::duration_cast<std::chrono::microseconds>(end - begin);std::cout << "It took me " << time_span_ms.count() << " milliseconds (ms).\n";std::cout << "It took me " << time_span_us.count() << " microseconds (us).\n";std::cout << std::endl;return 0;
}

在这里插入图片描述

Printing out 1000 stars...
****************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************
It took me 33 milliseconds (ms).
It took me 33908 microseconds (us).请按任意键继续. . .

References

[1] Yongqiang Cheng, https://yongqiang.blog.csdn.net/

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://xiahunao.cn/news/3245190.html

如若内容造成侵权/违法违规/事实不符,请联系瞎胡闹网进行投诉反馈,一经查实,立即删除!

相关文章

OpenCV 棋盘格相机标定(保姆版)

目录 一、概述 1.1标定原理 1.2实现步骤 1.3应用场景 二、代码 2.1 cv2.calibrateCamera函数 2.1.1输入参数 2.1.2输出参数 2.2完整代码 三、实现效果 3.1处理图像 3.2内参与畸变系数 一、概述 使用 OpenCV 进行相机标定&#xff0c;通常需要拍摄多张包含棋盘格标定…

第一次参加数学建模竞赛新手小白备赛经验贴

2024年暑假已经来临&#xff0c;下半年的数学建模竞赛非常多&#xff0c;许多同学可能是第一次参赛&#xff0c;对于如何准备感到迷茫和无从下手。在这种情况下&#xff0c;我们将分享一些备赛的小技巧&#xff0c;帮助大家在这个暑假更好的入门&#xff0c;即便是零基础的小白…

Python面试宝典第14题:背包问题

题目 现有编号从 0 到 n - 1 的 n 个背包&#xff0c;给你两个下标从 0 开始的整数数组 capacity 和 rocks 。第 i 个背包最大可以装 capacity[i] 块石头&#xff0c;当前已经装了 rocks[i] 块石头&#xff08;0 < rocks[i] < capacity[i]&#xff09;。另给你一个整数 a…

牛客周赛 Round 51 (C++)

目录 A-小红的同余_牛客周赛 Round 51 (nowcoder.com) 思路&#xff1a; 代码&#xff1a; B-小红的三倍数_牛客周赛 Round 51 (nowcoder.com) 思路&#xff1a; 代码&#xff1a; C-小红充电_牛客周赛 Round 51 (nowcoder.com) 思路&#xff1a; 代码&#xff1a; …

SHOT(方向直方图)

Salti等人在2014年提出一种表面匹配的局部三维描述子SHOT。Salti等人将现有三维局部特征描述方法分为两类&#xff0c;即基于特征的描述方法与基于直方图的描述方法&#xff0c;并分析了两种方法的优势&#xff0c;提出基于特征的局部特征描述方法要比后者在特征的描述能力上更…

基于视觉工具箱和背景差法的行人检测,行走轨迹跟踪,人员行走习惯统计matlab仿真

目录 1.算法运行效果图预览 2.算法运行软件版本 3.部分核心程序 4.算法理论概述 5.算法完整程序工程 1.算法运行效果图预览 (完整程序运行后无水印) 在三维图中&#xff0c;幅度越大&#xff0c;则表示人员更习惯的行走路线。 2.算法运行软件版本 matlab2022a 3.部分核…

【北京迅为】《i.MX8MM嵌入式Linux开发指南》-第一篇 嵌入式Linux入门篇-第二十九章 NFS服务器的搭建和使用

i.MX8MM处理器采用了先进的14LPCFinFET工艺&#xff0c;提供更快的速度和更高的电源效率;四核Cortex-A53&#xff0c;单核Cortex-M4&#xff0c;多达五个内核 &#xff0c;主频高达1.8GHz&#xff0c;2G DDR4内存、8G EMMC存储。千兆工业级以太网、MIPI-DSI、USB HOST、WIFI/BT…

VS2022配置Qt环境

文章目录 前言VS2022写Qt的好处下载插件前提条件离线下载在线安装配置VS For Qt 创建项目总结 前言 在许多开发环境中&#xff0c;Visual Studio 2022&#xff08;VS2022&#xff09;和Qt都是非常重要的工具。VS2022是微软开发的一款强大的集成开发环境&#xff08;IDE&#x…

前缀和算法——部分OJ题详解

&#xff08;文章的题目解释可能存在一些问题&#xff0c;欢迎各位小伙伴私信或评论指点&#xff08;双手合十&#xff09;&#xff09; 关于前缀和算法 前缀和算法解决的是“快速得出一个连续区间的和”&#xff0c;以前求区间和的时间复杂度是O(N)&#xff0c;使用前缀和可…

STM32智能农业灌溉系统教程

目录 引言环境准备智能农业灌溉系统基础代码实现&#xff1a;实现智能农业灌溉系统 4.1 数据采集模块 4.2 数据处理与决策模块 4.3 通信与网络系统实现 4.4 用户界面与数据可视化应用场景&#xff1a;农业灌溉管理与优化问题解决方案与优化收尾与总结 1. 引言 智能农业灌溉系…

react基础样式控制

行内样式 <div style{{width:500px, height:300px,background:#ccc,margin:200px auto}}>文本</div> class类名 注意&#xff1a;在react中使用class类名必须使用className 在外部src下新建index.css文件写入你的样式 .fontcolor{color:red } 在用到的页面引入…

基于springboot和mybatis的RealWorld后端项目实战二之实现tag接口

修改pom.xml 新增tag数据表 SET FOREIGN_KEY_CHECKS0;-- ---------------------------- -- Table structure for tags -- ---------------------------- DROP TABLE IF EXISTS tags; CREATE TABLE tags (id bigint(20) NOT NULL AUTO_INCREMENT,name varchar(255) NOT NULL,PR…

IP地址定位与智慧城市和智能交通

智慧城市和智能交通是现代城市发展的关键领域&#xff0c;通过先进技术提升城市管理和居民生活质量。IP地址定位在交通监控、智能路灯管理等方面发挥了重要作用&#xff0c;本文将深入探讨其技术实现及应用。 交通监控与优化 通过IP地址连接交通传感器和摄像头&#xff0c;可…

Hive 函数

分类 Hive 的函数分为两大类&#xff1a;内置函数&#xff08;Built-in-Functions&#xff09;、用户自定义函数&#xff08;User-Defined-Functions&#xff09;&#xff1b;内置函数可分为&#xff1a;数值类型函数、日期类型函数、字符串类型函数、集合函数等&#xff1b;用…

使用llama.cpp量化模型

文章目录 概要整体实验流程技术细节小结 概要 大模型量化是指在保持模型性能尽可能不变的情况下&#xff0c;通过减少模型参数的位数来降低模型的计算和存储成本。本次实验环境为魔搭社区提供的免费GPU环境&#xff08;24G&#xff09;&#xff0c;使用Llama.cpp进行4bit量化可…

行业模板|DataEase物业管理大屏模板推荐

DataEase开源数据可视化分析工具于2022年6月发布模板市场&#xff08;https://templates-de.fit2cloud.com&#xff09;&#xff0c;并于2024年1月新增适用于DataEase v2版本的模板分类。模板市场旨在为DataEase用户提供专业、美观、拿来即用的大屏模板&#xff0c;方便用户根据…

基于搜索二叉树的停车收费管理系统

系统效果&#xff1a;录入汽车信息 查看汽车信息 收费信息查看 查询车库车辆 代码展示&#xff1a; //SearchBinaryTree.h #pragma once #include<iostream> #include<string> #include<time.h> #include<Windows.h> using namespace std;template<…

FPGA资源容量

Kintex™ 7 https://www.amd.com/zh-tw/products/adaptive-socs-and-fpgas/fpga/kintex-7.html#product-table AMD Zynq™ 7000 SoC https://www.amd.com/en/products/adaptive-socs-and-fpgas/soc/zynq-7000.html#product-table AMD Zynq™ UltraScale™ RFSoC 第一代 AMD Z…

gemini-pro-vision 看图说话

一、安装 pip install -U langchain-google-vertexai 二、设置访问权限 申请服务账号json格式key 三、完整代码 import gradio as gr import json import base64 from pathlib import Path import os import time import requests from fastapi import FastAPI, UploadFile,…

图扑低代码数字孪生 Web SCADA 智慧钢厂

2024 年 4 月&#xff0c;中国钢铁工业协会发布了《钢铁行业数字化转型评估报告&#xff08;2023年&#xff09;》&#xff08;以下简称《报告》&#xff09;。《报告》指出&#xff0c;绝大部分钢铁企业建立了数字化转型相关管理组织和团队&#xff0c;并加强其规划落实&#…