我为我正在处理的项目创建了一个单元测试套件。我的单元测试过去运行得非常快......其中 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)