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

3

6

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?

Uredo answered 10/3, 2015 at 17:25 Comment(3)
In my life thusfar I have not come across a number "evenly divisible by zero"Condense
@Condense Oops, I meant 1000. Fixed.Uredo
Note that this is not the case in more recent version of Boost, but @Ilya Popov answer seems to be a good explanation.Schinica
P
8

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.

Pageboy answered 31/5, 2015 at 18:21 Comment(0)
C
2

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

Condense answered 10/3, 2015 at 22:16 Comment(2)
That's a lot of useful information, and I'm in no doubt about microseconds being the unit that Boost reports. My question is why it uses the abbreviation "mks" to indicate microseconds. Does "mks" generally mean microseconds in the world at large?Uredo
@OldPeculier If that was the whole question, you could have done without the context. Regardless, with the information from my answer I can guess at a potential German background here. Seeing that this uses the deprecated Boost Timer interfaces, it's probably old, possibly dating back from when library acceptance reviews were less stringent?Condense
P
1

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.)

Prognostic answered 13/5, 2015 at 18:44 Comment(5)
I don't see what your answer added. Most (if not all) of the facts were mentioned - with exact code - in my answer. I share your idea that it might be a spurious sign showing german origin. I also agree that it should be consistent. But we're not writing opinion pieces here (post that to the boost mailing lists :))Condense
Thanks @Rhubbarb, this is useful. It's difficult to prove that something is non-standard except by observing that it's almost never used, and that seems to be the case here. Your thoughts on alternatives are in the spirit of the question and most helpful. Thanks.Uredo
@OldPeculier Just to clarify: it's the "mks" that's used most of the time, with the "ms" used only rarely (as you alluded to, and as shown in sehe's code fragment). In saying that, really it will depend on the system's timer granularity (again as sehe described and tabulated) or the "modulo class" of the values produced and the common factor of 1000 and the time step.Prognostic
I forgot to mention that I searched both online, and through various books I have on units of measurement, but could find no trace of "mks" used for the microsecond. I was really trying to indicate the apparent "non-standardness" of this abbreviation. sehe mentioned a possible German origin; the Boost Test developer originates from Ukraine. I did not find an international explanation though.Prognostic
Gennadiy Rozental, the developer of Boost Test is here on Stack Overflow. @GennadiyRozental: only you can provide the definitive answer to OP's (OldPeculier's) question! :)Prognostic

© 2022 - 2024 — McMap. All rights reserved.