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

Linux应用开发之网络套接字编程(实例篇)

服务端与客户端单连接 服务端代码 #include <sys/socket.h> #include <sys/types.h> #include <netinet/in.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <arpa/inet.h> #include <pthread.h> …...

调用支付宝接口响应40004 SYSTEM_ERROR问题排查

在对接支付宝API的时候&#xff0c;遇到了一些问题&#xff0c;记录一下排查过程。 Body:{"datadigital_fincloud_generalsaas_face_certify_initialize_response":{"msg":"Business Failed","code":"40004","sub_msg…...

EtherNet/IP转DeviceNet协议网关详解

一&#xff0c;设备主要功能 疆鸿智能JH-DVN-EIP本产品是自主研发的一款EtherNet/IP从站功能的通讯网关。该产品主要功能是连接DeviceNet总线和EtherNet/IP网络&#xff0c;本网关连接到EtherNet/IP总线中做为从站使用&#xff0c;连接到DeviceNet总线中做为从站使用。 在自动…...

视频行为标注工具BehaviLabel(源码+使用介绍+Windows.Exe版本)

前言&#xff1a; 最近在做行为检测相关的模型&#xff0c;用的是时空图卷积网络&#xff08;STGCN&#xff09;&#xff0c;但原有kinetic-400数据集数据质量较低&#xff0c;需要进行细粒度的标注&#xff0c;同时粗略搜了下已有开源工具基本都集中于图像分割这块&#xff0c…...

[大语言模型]在个人电脑上部署ollama 并进行管理,最后配置AI程序开发助手.

ollama官网: 下载 https://ollama.com/ 安装 查看可以使用的模型 https://ollama.com/search 例如 https://ollama.com/library/deepseek-r1/tags # deepseek-r1:7bollama pull deepseek-r1:7b改token数量为409622 16384 ollama命令说明 ollama serve #&#xff1a…...

破解路内监管盲区:免布线低位视频桩重塑停车管理新标准

城市路内停车管理常因行道树遮挡、高位设备盲区等问题&#xff0c;导致车牌识别率低、逃费率高&#xff0c;传统模式在复杂路段束手无策。免布线低位视频桩凭借超低视角部署与智能算法&#xff0c;正成为破局关键。该设备安装于车位侧方0.5-0.7米高度&#xff0c;直接规避树枝遮…...

Python学习(8) ----- Python的类与对象

Python 中的类&#xff08;Class&#xff09;与对象&#xff08;Object&#xff09;是面向对象编程&#xff08;OOP&#xff09;的核心。我们可以通过“类是模板&#xff0c;对象是实例”来理解它们的关系。 &#x1f9f1; 一句话理解&#xff1a; 类就像“图纸”&#xff0c;对…...

高分辨率图像合成归一化流扩展

大家读完觉得有帮助记得关注和点赞&#xff01;&#xff01;&#xff01; 1 摘要 我们提出了STARFlow&#xff0c;一种基于归一化流的可扩展生成模型&#xff0c;它在高分辨率图像合成方面取得了强大的性能。STARFlow的主要构建块是Transformer自回归流&#xff08;TARFlow&am…...

MySQL体系架构解析(三):MySQL目录与启动配置全解析

MySQL中的目录和文件 bin目录 在 MySQL 的安装目录下有一个特别重要的 bin 目录&#xff0c;这个目录下存放着许多可执行文件。与其他系统的可执行文件类似&#xff0c;这些可执行文件都是与服务器和客户端程序相关的。 启动MySQL服务器程序 在 UNIX 系统中&#xff0c;用…...

如何通过git命令查看项目连接的仓库地址?

要通过 Git 命令查看项目连接的仓库地址&#xff0c;您可以使用以下几种方法&#xff1a; 1. 查看所有远程仓库地址 使用 git remote -v 命令&#xff0c;它会显示项目中配置的所有远程仓库及其对应的 URL&#xff1a; git remote -v输出示例&#xff1a; origin https://…...