How Dec compares with rust_decimal, fastnum and native f64 across the operations a trading system runs on
a hot path. Every number is nanoseconds for one operation, taken as the median
over 1,024 values.
Each chart is scaled to its own slowest bar, so a chart shows who wins that
operation and by how much, not how operations compare with each other.
f64 is drawn in grey because it is the inexact reference, not a
decimal competing on correctness.
Compare two values
Add into an accumulator
Multiply price by size
Divide price by size
Square root of a price
Square root through f64
Round to 2 decimal places
Round to a 0.01 step
Floor to an integer
Ceiling to an integer
Convert to f64
Convert from f64
Parse from a string
Format to a string
Parse a batch into a fresh Vec
Allocate and copy a Vec
The parser accumulates in a u64 and promotes to u128 once a mantissa passes 19 digits, so the cost of that promotion is visible as the curve steepens past the boundary.
Rendering walks the digits it has, so the curve is the cost of the digits themselves rather than of any one value.
The same numbers as one table.
| operation | f64 | Dec | rust_decimal | fastnum |
|---|---|---|---|---|
| cmp | 0.14 | 0.54 | 4.63 | 5.43 |
| add | 0.47 | 1.15 | 2.49 | 8.55 |
| mul | 0.27 | 3.89 | 7.25 | 7.31 |
| div | 1.03 | 19.38 | 32.99 | 101.20 |
| sqrt | 1.55 | 55.65 | 1763.48 | 9683.39 |
| sqrt_approx | 1.56 | 17.18 | — | — |
| round_dp | 1.40 | 5.86 | 16.72 | 11.31 |
| round_to_step | 1.59 | 4.42 | 31.48 | 28.08 |
| floor | 1.80 | 4.93 | 8.54 | 14.39 |
| ceil | 1.81 | 5.19 | 9.16 | 19.82 |
| to_f64 | — | 1.65 | 17.36 | 2.89 |
| from_f64 | — | 11.78 | 96.69 | 96.63 |
| parse | 9.99 | 12.04 | 13.44 | 19.08 |
| format | 76.50 | 31.73 | 40.51 | 61.87 |
| collect | 10.79 | 13.70 | 12.81 | 12.71 |
| clone | 0.10 | 0.12 | 0.12 | 0.29 |