c++ - 每次都赶上测试框架长链接时间
问题描述
我目前正在尝试使用 Catch 测试框架。我正在使用 cmake 来构建我的项目,目前我只是将所有 .h 和 .c 文件放在一起。出于测试目的,我取出了我的实际“主要”并将其替换为 Catch 的样本阶乘示例。我有两个文件:
// testmain.cpp
#define CATCH_CONFIG_MAIN
#include <catch2/catch.hpp>
和
//test.cpp
#include "catch2/catch.hpp"
int Factorial( int number ) {
return number <= 1 ? number : Factorial( number - 1 ) * number; // fail
// return number <= 1 ? 1 : Factorial( number - 1 ) * number; // pass
}
TEST_CASE( "Factorial of 0 is 1 (fail)", "[single-file]" ) {
REQUIRE( Factorial(0) == 1 );
}
TEST_CASE( "Factorials of 1 and higher are computed (pass)", "[single-file]" ) {
REQUIRE( Factorial(1) == 1 );
REQUIRE( Factorial(2) == 2 );
REQUIRE( Factorial(3) == 6 );
REQUIRE( Factorial(10) == 3628800 );
}
现在发生的事情是它花费 3 秒构建和 1 分钟链接。在所有链接(1+分钟)之后,我得到了测试结果。我遵循以下两个教程,其中提到将这两个文件分开。
我阅读了 Catch 教程: https ://github.com/catchorg/Catch2/blob/master/docs/tutorial.md
和
“慢编译”维基页面: https ://github.com/catchorg/Catch2/blob/master/docs/slow-compiles.md
我不太确定为什么链接需要这么长时间。有没有人遇到过这样的问题?
更新:
有关我的环境的更多信息:
cmake 3.14.0-rc1
g++ 8.1.0
解决方案
因此,从这个已知问题来看:
github.com/catchorg/Catch2/issues/1205
Mingw 在链接时间优化方面真的很糟糕。然而; 我偶然发现了一个适合我的解决方案。将 cmake 构建类型设置为
RELWITHDEBINFO
似乎将链接速度提高了 10 倍。
推荐阅读
- javascript - 为什么 setBusy 不能在我的控制器中工作?
- python - 如何根据当前日期创建文件结构?
- file-upload - 边缘浏览器的严格模式下不允许分配给只读属性
- angular - 在某个点中止 concat observables
- c - strncpy 调用的段错误
- python-3.x - 识别和计算(时间序列)数据框中列的交替部分
- mysql - R 到 MySQL 查询
- php - 在 Ubuntu 18.04 上的本地机器上设置现有 Laravel 项目时出现问题
- nginx - nginx prometheus exporter 收集的指标是之前收集的,具有相同的名称和标签值
- java - 导出为 HTML 时如何使报表大小适应屏幕大小