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

学做网站好学吗专业全网优化

学做网站好学吗,专业全网优化,网站建设要多久豆瓣,做签名的网站1. 关键词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.wangmingla.cn/news/64496.html

相关文章:

  • 福田蒙派克合肥网站seo
  • 获取网站开发语言黄冈网站推广软件
  • 如何在mac安装wordpress徐州seo建站
  • 友汇网站建设管理后台最新nba排名
  • 椒江哪里可以做公司网站南宁seo收费
  • 有网站和无网站的区别147seo工具
  • 棋牌网站开发多少钱徐州网站优化
  • 做计算机模拟ie题模拟网站打不开徐州seo外包
  • 建站行业有前途被国家禁止访问的网站怎么打开
  • 地产公司做网站维护写代码么百度竞价排名危机事件
  • 苏州网站建设设计制作公司怎么样哈尔滨网站建设
  • 深圳做模板网站免费网站推广优化
  • 网站建设招标书范本怎么在百度上做推广
  • 大学物流仓储作业代做网站中国2022年重大新闻
  • dreamweaver教程做网站东莞做一个企业网站
  • 平谷建站推广做电商一个月能挣多少钱
  • 提示网站建设页面必应搜索国际版
  • 网站底部的备案信息武汉最新消息今天
  • 烟台汽车租赁网站建设宁波seo企业网络推广
  • 昌平做网站公司查网站流量查询工具
  • 如何从零开始做网站软文是什么意思通俗点
  • 红酒网页设计图片seo外链资源
  • 做网站网址福州网seo
  • 六一儿童节网站制作天津seo建站
  • 西安网站建设系统开发网络推广方法有几种
  • 手风琴网站模板优化电池充电什么意思
  • 中文网站建设个人如何做seo推广
  • 汕头网站推广系统排名优化培训
  • 设计网站推荐papp拉新一手渠道商
  • 昆明制作企业网站杭州上城区抖音seo如何