Benchmark tool library for c++ code

本文探讨了Benchmark在科学与技术中的含义,特别是在计算机领域的性能评估。文章介绍了Benchmark的重要原则,如相关性、代表性、公平性等,并列举了不同类型如真实程序、组件/微基准和合成基准。此外,还提到了一些常用的C++ Benchmark工具,如CppBenchmark、sltbench、nonius、hayai和google/benchmark,并给出了它们的使用示例和特点。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Benchmark是什么?

Wikipedia解释

如下几类:

  • Business and economics(商业和经济)

    • Benchmarking, evaluating performance within organizations(基准测试是将业务流程和绩效指标与其他公司的行业最佳和最佳实践进行比较的做法。 通常测量的维度是质量、时间和成本)
    • Benchmark price (基准价格 (BP) 是国际市场特定部分中每单位数量的价格,由在伦敦金属交易所等市场上一贯出口最大数量或数量的国家或生产者组织设定。 [1] [2] 这个价格是定期设定的,通常是每月一次,作为国际贸易的指导方针。)
    • Benchmark (crude oil), oil-specific practices (基准原油或标记原油是用作原油买卖双方参考价格的原油。有三个主要基准,即西德克萨斯中质原油 (WTI)、布伦特混合原油和迪拜原油。)
    • Benchmark, an investment performance attribution (投资业绩归因是一组技术,业绩分析师用来解释为什么投资组合的业绩与基准不同)
  • Science and technology (科学与技术)

    • Benchmark (surveying), a point of known elevation marked for the purpose of surveying (基准、基准或测量基准这一术语起源于测量员在石头结构中凿出的水平标记)
    • Benchmarking (geolocating), an activity involving finding benchmarks (是参与者寻找基准(也称为调查标记或大地控制点)的业余爱好活动)
    • Benchmark (computing), the result of running a computer program to assess performance (在计算中,基准是运行一个计算机程序、一组程序或其他操作的行为,以评估一个对象的相对性能,通常是通过对它运行许多标准测试和试验。 [1] 术语基准也通常用于精心设计的基准测试程序本身。)
    • Benchmark, a best-performing, or gold standard test in medicine and statistics (医学和统计学中表现最佳或黄金标准的测试)

    和我们相关的是Science and technology中的Benchmark (computing),主要通过考察一个计算机程序、一组程序、其他操作行为,然后对一个对象进行性能评估。

Benchmark (computing)

  • Benchmark原则

    1. Relevance: Benchmarks should measure relatively vital features.(基准应该衡量相对重要的特征)
    2. Representativeness: Benchmark performance metrics should be broadly accepted by industry and academia.(代表性:基准性能指标应被业界和学术界广泛接受)
    3. Equity: All systems should be fairly compared.(公平:所有系统都应该被公平地比较)
    4. Repeatability: Benchmark results can be verified.(重复性:可以验证基准测试结果)
    5. Cost-effectiveness: Benchmark tests are economical.(成本效益:基准测试是经济的)
    6. Scalability: Benchmark tests should work across systems possessing a range of resources from low to high.(可扩展性:基准测试应该适用于拥有从低到高的一系列资源的系统)
    7. Transparency: Benchmark metrics should be easy to understand.(透明度:基准指标应该易于理解)
  • Benchmark类型

    1. Real program (真正的程序)
      • word processing software(文本处理程序)
      • tool software of CAD(CAD软件工具)
      • user’s application software (i.e.: MIS) (用户应用程序)
    2. Component Benchmark / Microbenchmark(组件benchmark,微benchmark)
      • core routine consists of a relatively small and specific piece of code. (由一段相对较小且特定的代码组成的核心例程)
      • measure performance of a computer’s basic components (测量计算机基本组件的性能)
      • may be used for automatic detection of computer’s hardware parameters like number of registers, cache size, memory latency, etc. (可用于自动检测计算机的硬件参数)
    3. Kernel(内核测试)
      • contains key codes
      • normally abstracted from actual program
      • popular kernel: Livermore loop
      • linpack benchmark (contains basic linear algebra subroutine written in FORTRAN language)
      • results are represented in Mflop/s.
    4. Synthetic Benchmark
      • Procedure for programming synthetic benchmark:
        • take statistics of all types of operations from many application programs
        • get proportion of each operation
        • write program based on the proportion above
      • Types of Synthetic Benchmark are:
      • These were the first general purpose industry standard computer benchmarks. They do not necessarily obtain high scores on modern pipelined computers.
    5. I/O benchmarks
    6. Database benchmarks
      • measure the throughput and response times of database management systems (DBMS)
    7. Parallel benchmarks
      • used on machines with multiple cores and/or processors, or systems consisting of multiple machines
  • 一些常用的benchmark测试工具

    内存、文件系统benchmark工具

    • Iometer – I/O subsystem measurement and characterization tool for single and clustered systems.
    • IOzone – Filesystem benchmark
    • 更多的参考Wikipedia链接
  • 一些个人想法

这里主要介绍了benchmark的原则(做基准测试要遵循的规则)、benchmark的类型(主要存在哪些类型的benchmark,当我们要进行benchmark测试时,首先要知道我们测试的主体是什么,在上述的类型中应该有它的归属)、一些常用的benchmark工具(针对那些通用的测试主体,已经前人开发的各个工具);那么我认为benchmark测试的流程应该如下:

针对C++代码进行Benchmark测试

回到我们主题,如何对C++代码进行Benchmark测试,这里以C++编写的logger日志库为例;按照我们上述Benchmark测试流程:

  1. Benchmark主体是什么?

    C++编写的logger日志库,应该属于Component Benchmark / Microbenchmark这一类;一段相对较小且特定的代码组成的核心例程

    ps: 多数我们用户态的C++代码,都能归属在Real program、Component Benchmark / Microbenchmark这两类。

  2. 是否存在现有的测试工具?

    目前没有。

  3. 需要自己编写测试工具

按照我们梳理的流程,需要自己编写测试工具。

那么针对我们C++代码Benchmark,自己可以编写简单的代码进行测试,比如如下代码,Timer用于测量shared_ptr使用make_shared和new两种方式初始化的执行时间:

#include <array>
#include <chrono>
#include <iostream>
#include <memory>

using TimePoint = std::chr
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值