2

I'm using Boost.Test (1.60.0) to test my projects. In order to identify the most time consuming tests, I wanted to know the test duration of every test in milliseconds. The total amount of time consumed by all tests would be also nice.

Does Boost.Test have such a feature? If not how can I implement such a time measurement on my own?

Aleph0
  • 5,816
  • 4
  • 29
  • 80
  • 1
    When running from command line try adding "log_level=all". This will set log verbosity to the maximum level. Boost will add test duration for each test case. – Uri Brecher Jun 02 '16 at 11:19
  • Thanks! That is what I'm looking for. It is possible to set the verbosity level using a `#define`, so that the switch is always on? The tests are run automatically on a different server and we are using different test frameworks in my company. – Aleph0 Jun 02 '16 at 11:23
  • yes. it's described in http://www.boost.org/doc/libs/1_60_0/libs/test/doc/html/boost_test/test_output/log_compil_time_configuration/log_ct_log_level.html#ref_log_level_explanations – Uri Brecher Jun 02 '16 at 11:36
  • The following line `boost::unit_test::unit_test_log.set_threshold_level(boost::unit_test::log_level::log_test_units);` did the job. Many thanks. – Aleph0 Jun 02 '16 at 11:48

2 Answers2

4

--log_level=unit_scope (or BOOST_TEST_LOG_LEVEL environmental variable)

This doesn't print any test messages but is verbose enough to print durations for each test suite and each test case in any suite.

Xeverous
  • 973
  • 1
  • 12
  • 25
1

You did not state which compiler you're using, but the reference to Boost means that it's likely to be gcc.

gcc has built-in support for runtime profiling called gprof. You will find plenty of documentation from a Google search, here's a tutorial to get you started.

Sam Varshavchik
  • 114,536
  • 5
  • 94
  • 148
  • Sorry, I'm using MSVC as a compiler. Actually, it would be nicer for me to have a console output at the end, stating the test time in second for every test case. Then summing the test time for every suite and finally the test time of all tests. The output should be triggered with a command line parameter. – Aleph0 Jun 02 '16 at 11:03