To: Heading_
Smallsite Design logo (SD) 390x390px

Smallsite Design

Support

25  Numbers

!

How we format numbers can go a long way to making them easier to take in.

When it comes to formatting numbers, it pays not to overthink a solution. We humans have had thousands of years of counting so that we prefer to see numbers as integers, even if there are decimal places added at the end.

However, when we start thinking of how we might show numeric values for comparison, we may start thinking that they might be more useful if all the values use the same unit. The thinking may extend to selecting a unit that most may be used to using in their daily lives, so requiring multiplying by a order of magnitude to scale them into the right range, especially if there is variation between individual values, and so aggregation may smooth those out.

The scenario to be used for demonstrating how we might format values is for the durations of several operations using PHP calculation engines, with a view to ascertaining which might be better used within a PHP program that might be highly dependent upon timing. Tabulated values will be used to show how we might think we can best format those values for comparison, beginning with an attempt to scale durations to be in our supposedly preferred seconds by multiplying them by one million.

The executions times (in seconds) per 1 million operations for several PHP calculation engines are:
#OperationFloat (double)PHP-DecimalBCMath (1000 digits)
aAddition0.0303.0750
bMultiplication0.0506.01500
cSquare root0.0608.02000

The issue with this is that we have to mentally calculate what the per operation duration is, which we can then use to calculate what the duration is for however many we are actually interested in. Even if it is necessary to use multiple cycles so that we can cater for variations between individual operations, still show the per operation duration.

The executions times (in µs) per operation for several PHP calculation engines are:
#OperationFloat (double)PHP-DecimalBCMath (1000 digits)
aAddition0.0303.0750
bMultiplication0.0506.01500
cSquare root0.0608.02000

While these now show per operation durations, because they are showing the values for the same unit, they appear radically different for each execution engine. While that may seem a valid basis for comparison, we really prefer to see values led by integers.

The executions times per operation for several PHP calculation engines, with units optimised for each for best presentation, are:
#OperationFloat (double)PHP-DecimalBCMath (1000 digits)
aAddition30 ns3.0 µs0.75 ms
bMultiplication50 ns6.0 µs1.5 ms
cSquare root60 ns8.0 µs2.0 ms

Even though the units for each engine are different, we seem to readily mentally adjust to being able to compare them because we can take in the values far more easily. However, Addition for BCMath may still present a visual challenge because it is fractional.

The executions times per operation for several PHP calculation engines, individually optimised for integer-leading, are:
#OperationFloat (double)PHP-DecimalBCMath (1000 digits)
aAddition30 ns3.0 µs750 µs
bMultiplication50 ns6.0 µs1.5 ms
cSquare root60 ns8.0 µs2.0 ms

Now each value is individually optimised for quick evaluation because they start with integers, which we can take in quickly almost subconsciously. The fact that they have different units does not seem to faze us in making comparisons, perhaps because we see that as scaling, which we can quickly mentally make after we have taken in the values themselves. For fractional or large values, we have to perform the complex parsing of the text to simultaneous get our preferred small integer and the scaling factor, which brings them fully into our consciousness, slowing us down.

General rule

Use the largest unit that shows the value as greater than 1.

In the context of ascertaining which engine is suitable for using in a PHP program, the actual integers could just be ignored and the order of magnitude indicated by the units be used. Without the integerisation, such a decision would not be immediately obvious. This highlights that presentation can favour which information is to be used for decision-making, while still showing individual details that may be of importance.

LinksLatest articles&Subsite links

Powered by   Smallsite Design  ©Smallsite™  Privacy   Manage\