当前位置: 首页 > news >正文

四川做网站百度知道网页入口

四川做网站,百度知道网页入口,苏州专业做网站的公司有哪些,axcure做网站ui1. 关键词2. 问题3. 解决思路4. 代码实现 4.1. timecount.h4.2. timecount.cpp 5. 测试代码6. 运行结果7. 源码地址 1. 关键词 C 时间处理 统计函数运行时间 跨平台 2. 问题 C如何简单便捷地实现“函数运行时间的统计”功能? 3. 解决思路 类的构造函数&#x…
  • 1. 关键词
  • 2. 问题
  • 3. 解决思路
  • 4. 代码实现
    • 4.1. timecount.h
    • 4.2. timecount.cpp
  • 5. 测试代码
  • 6. 运行结果
  • 7. 源码地址

1. 关键词

C++ 时间处理 统计函数运行时间 跨平台

2. 问题

C++如何简单便捷地实现“函数运行时间的统计”功能?

3. 解决思路

  • 类的构造函数:会在对象初始化的时候被调用。
  • 类的析构函数:会在对象销毁的时候被调用。
  • 局部对象的生命周期:对象实例化(也就是初始化)时开始,退出作用域时结束。

4. 代码实现

4.1. timecount.h


#pragma once#include <cstdint>
#include <atomic>
#include <string>namespace cutl
{/*** @brief A simple time counter class to measure the execution time of a function.**/class timecount{public:/*** @brief Construct a new timecount object* The constructor will record the begin time of the function calling.* @param func_name*/timecount(const std::string &func_name);/*** @brief Destroy the timecount object* The desctructor will record the end time of the function calling and calculate the execution time.*/~timecount();private:std::string func_name_;std::atomic<uint64_t> start_time_;};} // namespace

4.2. timecount.cpp

#include "timecount.h"
#include "timeutil.h"
#include "strfmt.h"
#include "inner/logger.h"namespace cutl
{timecount::timecount(const std::string &func_name): func_name_(func_name){start_time_ = clocktime(timeunit::us);}timecount::~timecount(){auto end_time = clocktime(timeunit::us);auto duration = end_time - start_time_;auto text = "[timecount] " + func_name_ + " used " + fmt_timeduration_us(duration);CUTL_LOGGER.info("", text);}
} // namespace

5. 测试代码

#pragma once#include <iostream>
#include "timecount.h"
#include "common.hpp"void TestTimecount()
{PrintTitle("timecount");cutl::timecount tcount("TestTimecount");std::cout << "TestTimecount begin" << std::endl;std::this_thread::sleep_for(std::chrono::seconds(1));std::cout << "TestTimecount end" << std::endl;
}

6. 运行结果

=============================================timecount==============================================
TestTimecount begin
TestTimecount end
[2024-05-19 22:34:35.853][I]]0x7ff844a9b100](cutl)  [timecount] TestTimecount used 01s.004955us

7. 源码地址

更多详细代码,请查看本人写的C++ 通用工具库: common_util, 本项目已开源,代码简洁,且有详细的文档和Demo。

http://www.ds6.com.cn/news/31540.html

相关文章:

  • 阿里巴巴国际站可以做网站吗关键词是网站seo的核心工作
  • 学校网站网站建设seo排名关键词
  • 网站开发ui公司推广策划方案
  • 深圳建站模板购买软件开发公司推荐
  • 公司做社交网站诈骗网建
  • 网站评论回复如何做实时热榜
  • 网站制作东莞seo网络营销外包
  • 如何免费做网站网页北京seo技术
  • 苏州手机网站建设服务西安百度推广优化公司
  • 榆林做网站电话企业快速建站
  • 网站收录入口申请企业网站的类型
  • 在哪个网站订酒店做申根签证seo服务哪家好
  • 派遣公司做网站的好处杭州百度推广代理商
  • 各类最牛网站建设如何做品牌宣传与推广
  • 网站是怎么优化推广的北京seo人员
  • 创业做网站站长之家ping
  • 内部优惠券网站怎么做百家港 seo服务
  • 郫县做网站数据分析网官网
  • 找公司做网站需要注意网络推广的工作内容是什么
  • 制作网站工具友情链接qq群
  • 外网建筑设计网站seo主管招聘
  • 中企动力邮箱seo三人行网站
  • 网站维护北京外贸营销网站建设介绍
  • 如何在自己网站上做支付宝吗公司推广方案
  • 常州网站建设开发合肥百度seo代理
  • 网站原型设计和版式设计网络营销一般月薪多少
  • 网站开发好公司济宁百度推广开户
  • 成都网站建设公司有哪些最近新闻摘抄50字
  • 做电子相册的大网站苏州做网站哪家比较好
  • 公安备案 个人网站拼多多关键词怎么优化