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

micro benchmark 使用经验

文章目录

    • User Guide

User Guide

  1. User Guide: https://github.com/google/benchmark/blob/main/docs/user_guide.md
#include <benchmark/benchmark.h>
#include <chrono>
#include <thread>void BM_DemoSleep(benchmark::State& state) {for (auto _ : state){//待测试的代码}
}
BENCHMARK(BM_DemoSleep); // 注册要测试的函数对象BENCHMARK_MAIN(); // main函数,运行benchmark初始化和执行

kNanosecond, kMicrosecond, kMillisecond, kSecond 千纳秒, 千微秒, 千毫秒, 千秒。

#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <fstream>
#include <ctime>
#include <stdio.h>
#include <math.h>
#include <iomanip>
#include <algorithm>
#include <chrono>
#include <thread>
#include <random>
#include <unordered_set>
#include "boost/unordered_set.hpp"#include <benchmark/benchmark.h>using namespace std;vector<int> datas;
vector<int> findDatas;void BM_Demo_1(benchmark::State& state) 
{//auto Parameters = state.range(0);//cout<<Parameters<<endl;unordered_set<int> data;for (auto _ : state){for(unsigned int i = 0; i < datas.size(); ++i) {data.insert(datas[i]);}for(unsigned int i = 0; i < findDatas.size(); ++i) {std::unordered_set<int>::const_iterator got = data.find(findDatas[i]);}//state.PauseTiming(); // pause timing//state.ResumeTiming(); // resume timing}
}void BM_Demo_2(benchmark::State& state) 
{boost::unordered_set<int> data;for (auto _ : state){for(unsigned int i = 0; i < datas.size(); ++i) {data.insert(datas[i]);} for(unsigned int i = 0; i < findDatas.size(); ++i) {boost::unordered_set<int>::const_iterator got = data.find(findDatas[i]);}}
}int main(int argc, char** argv) 
{::benchmark::Initialize(&argc, argv); if (::benchmark::ReportUnrecognizedArguments(argc, argv)) {return 1;}const int nrolls=10000;  // number of experimentsstd::default_random_engine generator;   std::uniform_int_distribution<int> distribution(0,5000);for (int i=0; i<nrolls; ++i) {     int number = distribution(generator); datas.push_back(number);}for (int i=0; i<nrolls*0.01; ++i) {     int number = distribution(generator); findDatas.push_back(number);}// The Arg method for passing parameters using the BENCHMARK macro to generate objects  // The parameters passed in will be stored inside the state object and obtained through the range method. // The parameter 0 required during the call corresponds to the first parameter//BENCHMARK(BM_Demo_1)->Arg(1);// Passing more Parameters//BENCHMARK(BM_Demo_1)->Args({10, 100});//BENCHMARK(BM_Demo_1)->Arg(10);//BENCHMARK(BM_Demo_1)->Arg(100);//BENCHMARK(BM_Demo_1)->RangeMultiplier(10)->Range(10, 1000);// multithreading// ->Threads(int t)// ->ThreadRange(int min_threads, int max_threads)// ->DenseThreadRange(int min_threads, int max_threads, int stride = 1);//::benchmark::RegisterBenchmark("BM_Demo_1", &BM_Demo_1)->Threads(10);// Repeat the iteration for 10 times, which means that the for (auto_: state) {} loop will iterate 10 times; Repeat the call 3 times//::benchmark::RegisterBenchmark("BM_Demo_1", &BM_Demo_1)->Iterations(10)->Repetitions(3)->Unit(benchmark::kMillisecond);// Set the display time unit : kNanosecond, kMicrosecond, kMillisecond, kSecond.//::benchmark::RegisterBenchmark("BM_Demo_1", &BM_Demo_1)->Unit(benchmark::kNanosecond);//Statistical analysis results will calculate the results of each time, and then output the analysis results: // mean, median, stddev: standard deviation, cv: standard deviation/mean. // Customized analysis results, such as minimum and maximum values/*::benchmark::RegisterBenchmark("BM_Demo_1", &BM_Demo_1)->ComputeStatistics("max", [](const std::vector<double>& v)->double{return *std::max_element(v.begin(), v.end());}, benchmark::kTime)->ComputeStatistics("min", [](const std::vector<double>& v)->double{return *std::min_element(v.begin(), v.end());}, benchmark::kTime);*///::benchmark::RegisterBenchmark("BM_Demo_1", &BM_Demo_1)->Iterations(100000)->Repetitions(1000)->Unit(benchmark::kNanosecond);//::benchmark::RegisterBenchmark("BM_Demo_2", &BM_Demo_2)->Iterations(100000)->Repetitions(1000)->Unit(benchmark::kNanosecond);::benchmark::RegisterBenchmark("BM_Demo_1", &BM_Demo_1)->Unit(benchmark::kNanosecond);::benchmark::RegisterBenchmark("BM_Demo_2", &BM_Demo_2)->Unit(benchmark::kNanosecond);::benchmark::RunSpecifiedBenchmarks(); ::benchmark::Shutdown(); return 0;
}

相关文章:

micro benchmark 使用经验

文章目录 User Guide User Guide User Guide: https://github.com/google/benchmark/blob/main/docs/user_guide.md #include <benchmark/benchmark.h> #include <chrono> #include <thread>void BM_DemoSleep(benchmark::State& state) {for (auto _ …...

nodejs发布静态https服务器

1、先用 npm init 创建一个package.json&#xff0c;然后添加依赖 node-static &#xff0c;package.json 如下&#xff1a; {"name": "freeswitch","version": "1.0.0","description": "test freeswitch for webrtc&…...

国产系统下开发QT程序总结

国产系统下开发QT程序总结 1. 国产系统简介 开发国产系统客户端的过程中&#xff0c;会出现兼容性问题。以下介绍Kylin和UOS环境下开发QT程序&#xff0c; 首先麒麟和统信这两个系统基于Ubuntu开发的。所以在Ubuntu开发理论上在国产系统上也能运行。芯片架构又分为amd,arm,mi…...

【Redis】redis入门+java操作redis

目录 一、Redis入门 1.1 Redis简介 1.2 Redis下载与安装 1.2.1 下载 1.2.2 linux安装 1.2.3 windows安装 1.3 Redis服务启动与停止 1.3.1 linux启动、停止Redis服务 1.3.2 windows启动、停止Redis服务 1.4 修改Redis启动密码 1.4.1 Linux修改设置 1.4.2 windows设…...

无涯教程-Android - Spinner函数

Spinner允许您从下拉菜单中选择一个项目 例如。使用Gmail应用程序时,将显示如下所示的下拉菜单,您需要从下拉菜单中选择一个项目。 Spinner Example 示例 本示例演示计算机的类别,您需要从类别中选择一个类别。 以下是修改后的主要Activity文件src/com.example.spinner/Andr…...

国标GB28181视频平台EasyGBS国标平台智能边缘计算网关关于小区电动车进电梯的应用方案设计

一、行业背景 随着人工智能技术的不断成熟与落地&#xff0c;各行各业也逐渐融入AI智能检测技术&#xff0c;尤其是在视频监控领域&#xff0c;通过AI视频智能检测与分析&#xff0c;可以大大提高视频的自动化、智能化监控能力。比如在小区的管理中&#xff0c;由电动车上楼入…...

supervisorctl(-jar)启动配置设置NACOS不同命名空间

背景 由于需要在上海服务器上面配置B测试环境&#xff0c;原本上面已有A测试环境&#xff0c;固需要将两套权限系统分开 可以使用不同的命名空间来隔离启动服务 注&#xff1a;本文章均不涉及公司机密 1、新建命名空间 命名空间默认会有一个public&#xff0c;并且不能删除&a…...

如何解决 Out Of Memory 的问题

背景 在用 Excel Importer 导入数据&#xff0c;当数据量超过 1w 行&#xff0c;经常会出现 OutOfMemory 的错误。&#xff08;用 Excel Exporter 导出数据时&#xff0c;也会有类似问题&#xff09;。 通常的表现症状如下&#xff0c;即在导入成功若干行之后&#xff0c;爆出…...

代码随想录训练营二刷第九天 | 字符串结束

总结 总体来说字符串的题目除了KMP之外难度不大&#xff0c;但是细节不少&#xff0c;有翻转的有双指针操作的。 此外一般使用双指针都是为了降低时间复杂度&#xff0c;从On2到On&#xff0c;链表除外。...

javaee spring jdbcTemplate的使用

依赖 <?xml version"1.0" encoding"UTF-8"?><project xmlns"http://maven.apache.org/POM/4.0.0" xmlns:xsi"http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation"http://maven.apache.org/POM/4.0.0 htt…...

qt day

#include "widget.h" #include "ui_widget.h" void Widget::my_slot() {} Widget::Widget(QWidget *parent): QWidget(parent), ui(new Ui::Widget) {ui->setupUi(this);this->setWindowIcon(QIcon(":/wodepeizhenshi.png"));//設置窗口的…...

Configurable Weather Parameters

1. Weather Parameters 2. Classification ClearNoon, CloudyNoon, WetNoon, WetCloudyNoon, SoftRainNoon, MidRainyNoon, HardRainNoon, ClearSunset, CloudySunset, WetSunset, WetCloudySunset, SoftRainSunset, MidRainSunset, HardRainSunset to do list: 可以关注一下…...

MySQL 8 数据清洗总结

MySQL 8 数据清洗三要素&#xff1a; 库表拷贝和数据备份数据清洗SQL数据清洗必杀技-存储过程 前提&#xff1a;数据库关联库表初始化和基础数据初始化&#xff1a; -- usc.t_project definitionCREATE TABLE t_project (id varchar(64) NOT NULL COMMENT 主键,tid varchar(…...

设计模式第九讲:常见重构技巧 - 去除不必要的!=

设计模式第九讲&#xff1a;常见重构技巧 - 去除不必要的! 项目中会存在大量判空代码&#xff0c;多么丑陋繁冗&#xff01;如何避免这种情况&#xff1f;我们是否滥用了判空呢&#xff1f;本文是设计模式第九讲&#xff0c;讲解常见重构技巧&#xff1a;去除不必要的! 文章目录…...

自动化安装系统问题记录

Cobbler 版本更新 https://github.com/cobbler/cobbler/releases Centos7/8 Cobbler 问题&#xff1a; 部署cobbler时&#xff0c;使用cobbler get-loaders从网络下载引导加载程序时提示命令未找到 解决&#xff1a; yum -y install syslinux Rockylinux9.2 Cobbler3.…...

centos7 docker安装记录

以下所有命令都在root用户下进行&#xff0c;若为普通用户&#xff0c;需要在所有命令前加上 sudo。 1、更新yum包 将yum包更新到最新 yum update2、安装需要的软件包 yum-util 提供yum-config-manager功能&#xff0c;另外两个是devicemapper驱动依赖的&#xff1b; yum …...

全网实时热点热榜事件API

全网热榜API 一、全网热榜二、使用步骤1、接口2、请求参数 三、 案例和demo 一、全网热榜 1个免费的帮助你获取全网热点事件的接口API 二、使用步骤 1、接口 重要提示:建议使用https协议,当https协议无法使用时再尝试使用http协议 请求方式: GET https://luckycola.com.cn…...

淘宝API接口:提高电商运营效率与用户体验的利器(淘宝API接口使用指南)

淘宝API接口&#xff1a;提高电商运营效率与用户体验的利器 随着电商行业的快速发展&#xff0c;淘宝作为国内最大的电商平台之一&#xff0c;不断探索和创新&#xff0c;以满足不断变化的用户需求和商家需求。其中&#xff0c;淘宝API接口便是其创新的一个重要方面。本文将深…...

智己 LS6 用实力和你卷,最强 800v ?

2023 成都车展期间&#xff0c;智己 LS6 正式公布预售价格&#xff0c;新车预售价为 23-30 万元。新车会在 10 月份进行上市&#xff0c;11 月正式交付。 此前我们对智己 LS6 做过非常详细的静态体验&#xff0c;感兴趣的可点击此链接了解。 造型方面&#xff0c;新车前脸相比…...

深入探索C语言自定义类型:打造你的编程世界

一、什么是自定义类型 C语言提供了丰富的内置类型&#xff0c;常见的有int, char, float, double, 以及各种指针。 除此之外&#xff0c;我们还能自己创建一些类型&#xff0c;这些类型称为自定义类型&#xff0c;如数组&#xff0c;结构体&#xff0c;枚举类型和联合体类型。 …...

生成xcframework

打包 XCFramework 的方法 XCFramework 是苹果推出的一种多平台二进制分发格式&#xff0c;可以包含多个架构和平台的代码。打包 XCFramework 通常用于分发库或框架。 使用 Xcode 命令行工具打包 通过 xcodebuild 命令可以打包 XCFramework。确保项目已经配置好需要支持的平台…...

label-studio的使用教程(导入本地路径)

文章目录 1. 准备环境2. 脚本启动2.1 Windows2.2 Linux 3. 安装label-studio机器学习后端3.1 pip安装(推荐)3.2 GitHub仓库安装 4. 后端配置4.1 yolo环境4.2 引入后端模型4.3 修改脚本4.4 启动后端 5. 标注工程5.1 创建工程5.2 配置图片路径5.3 配置工程类型标签5.4 配置模型5.…...

智能在线客服平台:数字化时代企业连接用户的 AI 中枢

随着互联网技术的飞速发展&#xff0c;消费者期望能够随时随地与企业进行交流。在线客服平台作为连接企业与客户的重要桥梁&#xff0c;不仅优化了客户体验&#xff0c;还提升了企业的服务效率和市场竞争力。本文将探讨在线客服平台的重要性、技术进展、实际应用&#xff0c;并…...

2025 后端自学UNIAPP【项目实战:旅游项目】6、我的收藏页面

代码框架视图 1、先添加一个获取收藏景点的列表请求 【在文件my_api.js文件中添加】 // 引入公共的请求封装 import http from ./my_http.js// 登录接口&#xff08;适配服务端返回 Token&#xff09; export const login async (code, avatar) > {const res await http…...

ArcGIS Pro制作水平横向图例+多级标注

今天介绍下载ArcGIS Pro中如何设置水平横向图例。 之前我们介绍了ArcGIS的横向图例制作&#xff1a;ArcGIS横向、多列图例、顺序重排、符号居中、批量更改图例符号等等&#xff08;ArcGIS出图图例8大技巧&#xff09;&#xff0c;那这次我们看看ArcGIS Pro如何更加快捷的操作。…...

Hive 存储格式深度解析:从 TextFile 到 ORC,如何选对数据存储方案?

在大数据处理领域&#xff0c;Hive 作为 Hadoop 生态中重要的数据仓库工具&#xff0c;其存储格式的选择直接影响数据存储成本、查询效率和计算资源消耗。面对 TextFile、SequenceFile、Parquet、RCFile、ORC 等多种存储格式&#xff0c;很多开发者常常陷入选择困境。本文将从底…...

React---day11

14.4 react-redux第三方库 提供connect、thunk之类的函数 以获取一个banner数据为例子 store&#xff1a; 我们在使用异步的时候理应是要使用中间件的&#xff0c;但是configureStore 已经自动集成了 redux-thunk&#xff0c;注意action里面要返回函数 import { configureS…...

MySQL 8.0 事务全面讲解

以下是一个结合两次回答的 MySQL 8.0 事务全面讲解&#xff0c;涵盖了事务的核心概念、操作示例、失败回滚、隔离级别、事务性 DDL 和 XA 事务等内容&#xff0c;并修正了查看隔离级别的命令。 MySQL 8.0 事务全面讲解 一、事务的核心概念&#xff08;ACID&#xff09; 事务是…...

群晖NAS如何在虚拟机创建飞牛NAS

套件中心下载安装Virtual Machine Manager 创建虚拟机 配置虚拟机 飞牛官网下载 https://iso.liveupdate.fnnas.com/x86_64/trim/fnos-0.9.2-863.iso 群晖NAS如何在虚拟机创建飞牛NAS - 个人信息分享...

怎么让Comfyui导出的图像不包含工作流信息,

为了数据安全&#xff0c;让Comfyui导出的图像不包含工作流信息&#xff0c;导出的图像就不会拖到comfyui中加载出来工作流。 ComfyUI的目录下node.py 直接移除 pnginfo&#xff08;推荐&#xff09;​​ 在 save_images 方法中&#xff0c;​​删除或注释掉所有与 metadata …...