2

我为我正在处理的项目创建了一个单元测试套件。我的单元测试过去运行得非常快......其中 200 多个将在几秒钟内运行。通常每个测试将花费不到 10 毫秒。现在,在使用 Valgrind 和 Gcov 时,每个测试可能需要超过 1.5 分钟才能运行!有没有人有过非常慢的单元测试的经验?Valgrind、gcov 或 Google Test 在任何特定情况下是否会导致程序执行显着减慢?更令人困惑的是,一些单元测试运行得很好(即非常快),而另一些则需要几秒钟才能运行。通常,当再次运行单元测试时,相同的测试需要不同的时间来运行。我基本上是想弄清楚瓶颈在哪里。下面是一个例子:

[ RUN      ] BandwidthAlgorithmTest.TerminalsOnly
[       OK ] BandwidthAlgorithmTest.TerminalsOnly (34 ms)
[ RUN      ] BandwidthAlgorithmTest.AlohaAndTerminals
[       OK ] BandwidthAlgorithmTest.AlohaAndTerminals (38 ms)
[ RUN      ] BandwidthAlgorithmTest.AllocatePeriodic
[       OK ] BandwidthAlgorithmTest.AllocatePeriodic (304 ms)
[ RUN      ] BandwidthAlgorithmTest.AllocatePeriodic_Disabled
[       OK ] BandwidthAlgorithmTest.AllocatePeriodic_Disabled (152 ms)
[ RUN      ] BandwidthAlgorithmTest.AllocateFair
[       OK ] BandwidthAlgorithmTest.AllocateFair (109 ms)
[ RUN      ] BandwidthAlgorithmTest.AllocateFair_Disabled
[       OK ] BandwidthAlgorithmTest.AllocateFair_Disabled (64 ms)
[----------] 12 tests from BandwidthAlgorithmTest (2763 ms total)

[----------] 7 tests from BacklogHelperTest
[ RUN      ] BacklogHelperTest.ChangeInrouteState
[       OK ] BacklogHelperTest.ChangeInrouteState (80613 ms)
[ RUN      ] BacklogHelperTest.GetInvalidInroute
[       OK ] BacklogHelperTest.GetInvalidInroute (98471 ms)
4

2 回答 2

3

如果你对 valgrind 的性能感到失望,你可以试试谷歌刚刚起步的 AddressSanitizer。http://blog.chromium.org/2011/06/testing-chromium-addresssanitizer-fast.html 它需要使用特殊的编译器重新编译您的代码,但不需要更改源代码级别。

于 2011-06-18T22:11:35.983 回答
0

这里提到了一个潜在的原因:https ://groups.google.com/forum/#!topic /gnu.gcc.help/aS3mQGzGE_4 - 似乎 gcov 在某处有一个 O(n^2) 步骤并且对长 ( CPP 后)源代码行,或类似这些行的东西。

于 2014-01-28T16:20:46.947 回答