Qt 5.9.1 Reference Documentation

Chapter 5: Writing a Benchmark

In this final chapter we will demonstrate how to write benchmarks using Qt Test.

在这个最后的章节,我们将展示怎样用Qt测试框架写一个基准线。

Writing a Benchmark
To create a benchmark we extend a test function with a QBENCHMARK macro. A benchmark test function will then typically consist of setup code and a QBENCHMARK macro that contains the code to be measured. This test function benchmarks QString::localeAwareCompare().
要创建一个基准线,我们需要用QBENCHMARK宏来扩展我们的的测试函数。一个基准线测试函数将会典型地由建立代码和一个包含被测试代码的宏组成。此处,我们的基准线测试函数用来测试QString::localeAwareCompare()函数。

void TestBenchmark::simple()
  {
      QString str1 = QLatin1String("This is a test string");
      QString str2 = QLatin1String("This is a test string");

QCOMPARE(str1.localeAwareCompare(str2), 0);

QBENCHMARK {
          str1.localeAwareCompare(str2);
      }
  }

Setup can be done at the beginning of the function, the clock is not running at this point. The code inside the QBENCHMARK macro will be measured, and possibly repeated several times in order to get an accurate measurement.

在函数的开始部分就完成了初始建立的工作,此时时钟并未开始运行。在QBENCHMARK宏中的代码将会被测试,而且基本上会被执行多次来确保测量的准确性。

Several back-ends are available and can be selected on the command line.

多个后端可以通过命令行来进行选择。

Data Functions
Data functions are useful for creating benchmarks that compare multiple data inputs, for example locale aware compare against standard compare.
数据函数对创建比较多种数据输入的基准线测试很有用处,例如本地比较和标准比较。

void TestBenchmark::multiple_data()
  {
      QTest::addColumn<bool>("useLocaleCompare");
      QTest::newRow("locale aware compare") << true;
      QTest::newRow("standard compare") << false;
  }

The test function then uses the data to determine what to benchmark.
这个测试函数即会用这些数据来进行基准测试。

void TestBenchmark::multiple()
  {
      QFETCH(bool, useLocaleCompare);
      QString str1 = QLatin1String("This is a test string");
      QString str2 = QLatin1String("This is a test string");

int result;
      if (useLocaleCompare) {
          QBENCHMARK {
              result = str1.localeAwareCompare(str2);
          }
      } else {
          QBENCHMARK {
              result = (str1 == str2);
          }
      }
      Q_UNUSED(result);
  }

The "if (useLocaleCompare)" switch is placed outside the QBENCHMARK macro to avoid measuring its overhead. Each benchmark test function can have one active QBENCHMARK macro.

代码中的if开关被放置在QBENCHMARK宏之外来避免测量开销。每个基准测试函数可以有一个激活的QBENCHMARK宏。

External Tools

Tools for handling and visualizing test data are available as part of the qtestlib-tools project. These include a tool for comparing performance data obtained from test runs and a utility to generate Web-based graphs of performance data.

处理和可视化测试数据的工具可以在qtestlib-tools工程中找到。这些工具包含比较测试运行后性能数据的比较功能和基于web的图表展示功能。

See the qtestlib-tools announcement for more information on these tools and a simple graphing example.

参考qtestlib-tools的发布声明来获取更多的信息和相关的简单图表示例。

Qt 5.9.1 参考手册 QtTest 第5章 写一个基准线相关推荐

  1. 《版式设计——日本平面设计师参考手册》—第1章应用对象样式

    本节书摘来自异步社区<版式设计--日本平面设计师参考手册>一书中的第1章应用对象样式,作者+Designing编辑部,更多章节内容可以访问云栖社区"异步社区"公众号查看 ...

  2. 《版式设计——日本平面设计师参考手册》—第1章段落样式和字符样式的基础知识...

    本节书摘来自异步社区<版式设计--日本平面设计师参考手册>一书中的第1章段落样式和字符样式的基础知识,作者+Designing编辑部,更多章节内容可以访问云栖社区"异步社区&qu ...

  3. 《版式设计——日本平面设计师参考手册》—第1章段落格式的设置

    本节书摘来自异步社区<版式设计--日本平面设计师参考手册>一书中的第1章段落格式的设置,作者+Designing编辑部,更多章节内容可以访问云栖社区"异步社区"公众号查 ...

  4. 《版式设计——日本平面设计师参考手册》—第1章如何存储旧版本的InDesign文件...

    本节书摘来自异步社区<版式设计--日本平面设计师参考手册>一书中的第1章如何存储旧版本的InDesign文件,作者+Designing编辑部,更多章节内容可以访问云栖社区"异步社 ...

  5. 《MySQL 8.0 参考手册》第 14 章 MySQL 数据字典

    文章目录 14.1 数据字典模式 数据字典升级过程 使用 MySQL 调试版本查看数据字典表 14.2 删除基于文件的元数据 14.3 事务型数据字典 14.4 数据字典缓存 14.5 INFORMA ...

  6. prolog参考手册学习(第一章)

    SWI-Prolog 5.6 Reference Manual "其中挑选了重要的部分放上来了" 简介 SWI-Prolog is a Prolog implementation ...

  7. qt xml组包_Qt 利用XML文档,写一个程序集合 二

    XML文档的读写 一个根节点,下面每一个子节点代表一个子程序,内容为子程序名字,图标路径,exe路径 /* * 读取XML配置文档 */ static int count_flag = 0; void ...

  8. Debian参考手册读书摘要

    Debian参考手册笔记 第1章 GNU/Linux教程 1.1.1 欢迎提示 /etc/motd中保存非GUI登录时的欢迎提示信息 Debian GNU/Linux jessie/sid foo t ...

  9. Spring Boot 2.0.0参考手册_中文版

    Spring Boot参考文档 第一部分:Spring Boot文档 1. 关于文档 Sring参考文档可以通过html,pdf和epub 三种形式得到.最新的文档可以从docs.spring.io/ ...

最新文章

  1. C语言结构联合位字段知识体系总结大学霸IT达人
  2. Windows Azure虚拟机概览
  3. Nuget发布Dll
  4. Springmvc,Spring MVC文件上传
  5. 使用Apache Kudu和Impala实现存储分层
  6. idle运行python_命令行启动python的IDLE
  7. java成员变量覆盖_java-成员变量的属性与成员函数的覆盖
  8. linux跟踪函数代码,linux ltrace-跟踪进程调用库函数的情况
  9. 洛谷 P3152 正整数序列
  10. Android 原生的人脸识别Camera+FaceDetector示例
  11. office2010每次打开总是出现配置进度
  12. 吉客云与金蝶云星空集成方案(吉客云主管库存)
  13. 利用机器学习方法确定各个特征的权重
  14. 二、Contiki移植
  15. python图片显示文本框_Python3 tkinter基础 Text image 文本框中插入图片
  16. 关于c / c++中power_bound的使用
  17. 解读《花木兰》中的木兰形象
  18. java poi 读取word_Java poi读取word文档(本篇只能读取text内容)
  19. 鉴源实验室丨汽车电子架构和CAN网络基础
  20. 华为公司员工待遇全面揭秘

热门文章

  1. 【区块链技术工坊46期】PPIO蒋鑫:椭圆曲线密码学简介
  2. linux本地dns文件,Linux本地dns配置文件详解
  3. Python 爬虫系列:爬取全球机场信息
  4. labview 各版本及其模块工具下载汇总
  5. Android中动态改变布局中控件的位置
  6. 写给2018年底的我的一封信
  7. 百度人工智能发展怎么样啦?开发者能做什么?
  8. 《A Template for Understanding Big Debt Crises》 pdf、mobi、epub下载
  9. PMP_第7章章节试题
  10. 开源论坛软件Flarum的安装