当前位置: 首页 > 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;枚举类型和联合体类型。 …...

利用最小二乘法找圆心和半径

#include <iostream> #include <vector> #include <cmath> #include <Eigen/Dense> // 需安装Eigen库用于矩阵运算 // 定义点结构 struct Point { double x, y; Point(double x_, double y_) : x(x_), y(y_) {} }; // 最小二乘法求圆心和半径 …...

观成科技:隐蔽隧道工具Ligolo-ng加密流量分析

1.工具介绍 Ligolo-ng是一款由go编写的高效隧道工具&#xff0c;该工具基于TUN接口实现其功能&#xff0c;利用反向TCP/TLS连接建立一条隐蔽的通信信道&#xff0c;支持使用Let’s Encrypt自动生成证书。Ligolo-ng的通信隐蔽性体现在其支持多种连接方式&#xff0c;适应复杂网…...

Cursor实现用excel数据填充word模版的方法

cursor主页&#xff1a;https://www.cursor.com/ 任务目标&#xff1a;把excel格式的数据里的单元格&#xff0c;按照某一个固定模版填充到word中 文章目录 注意事项逐步生成程序1. 确定格式2. 调试程序 注意事项 直接给一个excel文件和最终呈现的word文件的示例&#xff0c;…...

React hook之useRef

React useRef 详解 useRef 是 React 提供的一个 Hook&#xff0c;用于在函数组件中创建可变的引用对象。它在 React 开发中有多种重要用途&#xff0c;下面我将全面详细地介绍它的特性和用法。 基本概念 1. 创建 ref const refContainer useRef(initialValue);initialValu…...

java 实现excel文件转pdf | 无水印 | 无限制

文章目录 目录 文章目录 前言 1.项目远程仓库配置 2.pom文件引入相关依赖 3.代码破解 二、Excel转PDF 1.代码实现 2.Aspose.License.xml 授权文件 总结 前言 java处理excel转pdf一直没找到什么好用的免费jar包工具,自己手写的难度,恐怕高级程序员花费一年的事件,也…...

【android bluetooth 框架分析 04】【bt-framework 层详解 1】【BluetoothProperties介绍】

1. BluetoothProperties介绍 libsysprop/srcs/android/sysprop/BluetoothProperties.sysprop BluetoothProperties.sysprop 是 Android AOSP 中的一种 系统属性定义文件&#xff08;System Property Definition File&#xff09;&#xff0c;用于声明和管理 Bluetooth 模块相…...

相机从app启动流程

一、流程框架图 二、具体流程分析 1、得到cameralist和对应的静态信息 目录如下: 重点代码分析: 启动相机前,先要通过getCameraIdList获取camera的个数以及id,然后可以通过getCameraCharacteristics获取对应id camera的capabilities(静态信息)进行一些openCamera前的…...

vue3+vite项目中使用.env文件环境变量方法

vue3vite项目中使用.env文件环境变量方法 .env文件作用命名规则常用的配置项示例使用方法注意事项在vite.config.js文件中读取环境变量方法 .env文件作用 .env 文件用于定义环境变量&#xff0c;这些变量可以在项目中通过 import.meta.env 进行访问。Vite 会自动加载这些环境变…...

DeepSeek 技术赋能无人农场协同作业:用 AI 重构农田管理 “神经网”

目录 一、引言二、DeepSeek 技术大揭秘2.1 核心架构解析2.2 关键技术剖析 三、智能农业无人农场协同作业现状3.1 发展现状概述3.2 协同作业模式介绍 四、DeepSeek 的 “农场奇妙游”4.1 数据处理与分析4.2 作物生长监测与预测4.3 病虫害防治4.4 农机协同作业调度 五、实际案例大…...

SAP学习笔记 - 开发26 - 前端Fiori开发 OData V2 和 V4 的差异 (Deepseek整理)

上一章用到了V2 的概念&#xff0c;其实 Fiori当中还有 V4&#xff0c;咱们这一章来总结一下 V2 和 V4。 SAP学习笔记 - 开发25 - 前端Fiori开发 Remote OData Service(使用远端Odata服务)&#xff0c;代理中间件&#xff08;ui5-middleware-simpleproxy&#xff09;-CSDN博客…...