Jeff Wofford
Jeff Wofford

Reputation: 11547

What is the "mks" unit reported by the Boost Unit Test Framework?

When executed with all logging enabled (e.g. test --log_level=all), a unit test created with the Boost Unit Test Framework will report how long an individual test case took with a message like this:

Leaving test case "testRecursiveSchedule"; testing time: 2196mks

The unit displayed there, mks, mystifies me. I understand that Meters-Kilograms-Seconds is a system for metric measurement, but Boost is clearly displaying a time measurement only. Shouldn't the unit in this case be ms if milliseconds or μs (or perhaps us) if microseconds? Is mks commonly understood as an abbreviation for microseconds?

Note that according to the Boost unit test framework source code, the unit displayed will be ms if the elapsed time happens to be evenly divisible by 1000, in which case it will be divided by 1000 before being displayed. That's consistent with the idea that mks is meant to imply microseconds.

But does it? Or is Boost being idiosyncratic here?

Upvotes: 6

Views: 1193

Answers (3)

Ilya Popov
Ilya Popov

Reputation: 4010

Here is my guess: mks means microseconds.

Gennadiy Rozental, the author of Boost.Test, is Russian-speaking, and in Russian microsecond is "микросекунда", abbreviated as "мкс", which can be transliterated as "mks". Sometimes I see "mks" accidentally appearing in works of Russian-speaking people.

Upvotes: 8

Rhubbarb
Rhubbarb

Reputation: 4388

The abbreviation "mks" seems to be non-standard. There are many better alternatives. These would be acceptable: "microsecond(s)", "microsec(s)", and perhaps "micro-s".

Possibly, "µs" is not used as this might confuse systems that still fail to support Unicode correctly, and also noting that there is more than one codepoint for mu: MICRO SIGN at U+00B5, GREEK SMALL LETTER MU at U+03BC. But often, "us" is used instead, as an English 'u' resembles a Greek mu 'µ'. (On units other than the second, it can look less like a word; e.g. the word-like "us", "um", "ug", as compared to the less-word-like microfarad "uF".)

The use of "mks" has at least two other areas of confusion. One is that there is a metric but not-quite-SI system of units called MKS (after metre, kilogram, second). Another is that both "m" and "k" (or sometimes, "K") are already prefixes, so "mks" looks like "milli-kilo-second", which is just a second.

What follows is just speculation…

In the Boost Test sources, the only place that mentions "mks" is boost/test/impl/compiler_log_formatter.ipp in a very odd block of code, but there are no comments giving any clue as to the reason for the choice of "mks". (The code is odd as it changes units based on particular values being exactly roundable, thus failing to indicate precision correctly, and upsetting, about 0.1% of the time, any scripts expecting always to see "mks".)

Possibly the "mk" was to indicate "my-kroh" phonetically (with a hard 'k'), as "mc" might look like "my-sroh", but then "mcs" would also look like "milli-centi-seconds" anyway.

(The only other mention of "mks", in Boost 1.57.0, seems to be mks_system in libs/units/example/test_system.hpp which I'm guessing relates to Boost Unit and the MKS system of units mentioned above.)

Upvotes: 1

sehe
sehe

Reputation: 392931

The mechanism used to time the tests is

    boost::timer tc_timer;
    test_unit_id bkup = m_curr_test_case;
    m_curr_test_case = tc.p_id;
    unit_test_monitor_t::error_level run_result = unit_test_monitor.execute_and_translate( tc );

    unsigned long elapsed = static_cast<unsigned long>( tc_timer.elapsed() * 1e6 );

Boost Timer is documented here and promises the following:

double elapsed() const                  // return elapsed time in seconds
   { return  double(std::clock() - _start_time) / CLOCKS_PER_SEC; }

As you can see Boost Tests passes microseconds to the observer's test_unit_finish implementations:

    BOOST_TEST_FOREACH( test_observer*, to, m_observers )
        to->test_unit_finish( tc, elapsed );

And they indeed print it typically as:

    if( elapsed % 1000 == 0 )
        output << elapsed/1000 << "ms";
    else
        output << elapsed << "mks";

or raw microseconds for XML:

if( tu.p_type == tut_case )
    ostr << "<TestingTime>" << elapsed << "</TestingTime>";

The effective accuracy depends on the system:

enter image description here

Upvotes: 2

Related Questions