Dec benchmarks

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.

cpu 12th Gen Intel(R) Core(TM) i7-12700H arch x86_64 rustc rustc 1.98.0 (88d9e12ae 2026-08-18) commit 623f30c (modified) measured 2026-09-05 15:23 UTC

Per operation

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.

f64 — inexact reference Dec rust_decimal fastnum

cmp

Compare two values

f64
0.14 ns
Dec
0.54 ns
rust_decimal
4.63 ns
fastnum
5.43 ns

add

Add into an accumulator

f64
0.47 ns
Dec
1.15 ns
rust_decimal
2.49 ns
fastnum
8.55 ns

mul

Multiply price by size

f64
0.27 ns
Dec
3.89 ns
rust_decimal
7.25 ns
fastnum
7.31 ns

div

Divide price by size

f64
1.03 ns
Dec
19.4 ns
rust_decimal
33.0 ns
fastnum
101 ns

sqrt

Square root of a price

f64
1.55 ns
Dec
55.6 ns
rust_decimal
1,763 ns
fastnum
9,683 ns

sqrt_approx

Square root through f64

f64
1.56 ns
Dec
17.2 ns
rust_decimal
not implemented
fastnum
not implemented

round_dp

Round to 2 decimal places

f64
1.40 ns
Dec
5.86 ns
rust_decimal
16.7 ns
fastnum
11.3 ns

round_to_step

Round to a 0.01 step

f64
1.59 ns
Dec
4.42 ns
rust_decimal
31.5 ns
fastnum
28.1 ns

floor

Floor to an integer

f64
1.80 ns
Dec
4.93 ns
rust_decimal
8.54 ns
fastnum
14.4 ns

ceil

Ceiling to an integer

f64
1.81 ns
Dec
5.19 ns
rust_decimal
9.16 ns
fastnum
19.8 ns

to_f64

Convert to f64

f64
not applicable
Dec
1.65 ns
rust_decimal
17.4 ns
fastnum
2.89 ns

from_f64

Convert from f64

f64
not applicable
Dec
11.8 ns
rust_decimal
96.7 ns
fastnum
96.6 ns

parse

Parse from a string

f64
9.99 ns
Dec
12.0 ns
rust_decimal
13.4 ns
fastnum
19.1 ns

format

Format to a string

f64
76.5 ns
Dec
31.7 ns
rust_decimal
40.5 ns
fastnum
61.9 ns

collect

Parse a batch into a fresh Vec

f64
10.8 ns
Dec
13.7 ns
rust_decimal
12.8 ns
fastnum
12.7 ns

clone

Allocate and copy a Vec

f64
0.10 ns
Dec
0.12 ns
rust_decimal
0.12 ns
fastnum
0.29 ns

Parsing by digit width

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.

010203040ns1481218192226Significant digits in the textf64 at 1: 5.40 nsf64 at 4: 8.22 nsf64 at 8: 11.3 nsf64 at 12: 12.2 nsf64 at 18: 13.5 nsf64 at 19: 13.9 nsf64 at 22: 36.7 nsf64 at 26: 38.4 nsf64Dec at 1: 6.77 nsDec at 4: 10.2 nsDec at 8: 14.4 nsDec at 12: 17.6 nsDec at 18: 23.5 nsDec at 19: 24.8 nsDec at 22: 30.4 nsDec at 26: 35.5 nsDecrust_decimal at 1: 10.7 nsrust_decimal at 4: 12.7 nsrust_decimal at 8: 16.3 nsrust_decimal at 12: 17.7 nsrust_decimal at 18: 21.2 nsrust_decimal at 19: 25.8 nsrust_decimal at 22: 33.7 nsrust_decimal at 26: 38.3 nsrust_decimalfastnum at 1: 16.6 nsfastnum at 4: 18.3 nsfastnum at 8: 19.7 nsfastnum at 12: 21.3 nsfastnum at 18: 24.1 nsfastnum at 19: 28.8 nsfastnum at 22: 33.7 nsfastnum at 26: 35.4 nsfastnum

Formatting by digit width

Rendering walks the digits it has, so the curve is the cost of the digits themselves rather than of any one value.

050100150ns1481218192226Significant digits in the valueDec at 1: 23.4 nsDec at 4: 29.2 nsDec at 8: 34.0 nsDec at 12: 38.8 nsDec at 18: 42.4 nsDec at 19: 44.0 nsDec at 22: 47.8 nsDec at 26: 52.6 nsDecrust_decimal at 1: 25.4 nsrust_decimal at 4: 33.9 nsrust_decimal at 8: 49.0 nsrust_decimal at 12: 65.9 nsrust_decimal at 18: 83.7 nsrust_decimal at 19: 86.9 nsrust_decimal at 22: 94.7 nsrust_decimal at 26: 107 nsrust_decimalfastnum at 1: 44.7 nsfastnum at 4: 67.2 nsfastnum at 8: 70.8 nsfastnum at 12: 87.2 nsfastnum at 18: 114 nsfastnum at 19: 119 nsfastnum at 22: 108 nsfastnum at 26: 125 nsfastnum

Summary

The same numbers as one table.

Nanoseconds per operation, median of criterion's samples, coloured by rank within each row: green fastest, then blue, amber, red. ★ marks the fastest decimal. Lower is better.
operationf64Decrust_decimalfastnum
cmp0.140.544.635.43
add0.471.152.498.55
mul0.273.897.257.31
div1.0319.3832.99101.20
sqrt1.5555.651763.489683.39
sqrt_approx1.5617.18——
round_dp1.405.8616.7211.31
round_to_step1.594.4231.4828.08
floor1.804.938.5414.39
ceil1.815.199.1619.82
to_f64—1.6517.362.89
from_f64—11.7896.6996.63
parse9.9912.0413.4419.08
format76.5031.7340.5161.87
collect10.7913.7012.8112.71
clone0.100.120.120.29