Closed craigfe closed 3 years ago
I agree that the measure should have its unit - currently, it does not do that due to a separation between the layout logic and the core (I mean, it's useless to know the unit when we benchmark - but it's not when we want to show result). I will make a PR about that next week,
An alternative that gives more flexibility to the renderer would be to have each MEASURE define its own unit type (like [> `Words ] or an extensible variant), which the renderer / user can then supply a to_string function for.
Hmmhmm, it's possible indeed but I think it's not necessary (or too over enginering for a small improvement).
Currently, the output renderers have the responsibility of assigning units to the measures. For instance:
I consider this to be backwards: the provider of the
monotonic_clock
instance is the only one who knows what its units are, as they are providing theget : unit -> float
function for this particular measure. I propose adding the following field to theS.MEASURE
signature:(Leaving the
None
case for unit-less quantities likemajor_collections
.) The renderer would then consume measures as{ name: string; unit: string option }
products (rather than the currentstring
just for the name), and be responsible for rendering that appropriately.An alternative that gives more flexibility to the renderer would be to have each
MEASURE
define its ownunit
type (like[> `Words ]
or an extensible variant), which the renderer / user can then supply ato_string
function for.