External baseline: floating against MPFR and libmpdec

Contract

This page records how much slower or faster floating is than the established C libraries on the same machine, with the same operands and the same measurement protocol: binary against MPFR for binary arithmetic and decimal_gda against libmpdec for GDA decimal arithmetic. It makes no API promise, and the numbers are evidence about one machine, one toolchain and one operand distribution, not a speed claim for every environment. Where floating is slower, the tables say so as measured; nothing here is tuned for the comparison, and no library code was changed for it.

The ratio of a cell is the net time of floating divided by the net time of the reference library; above 1 means floating is slower. A net time is the time of the operation without the loop around it: every block of a case is paired with a block of its null (the same loop without the library call), and the net time is the median of the differences of the pairs. The bracketed interval is a 95% bootstrap interval over rounds and pairs, and the interval of the ratio resamples the two sides independently; the method, with its formulas and its fixed rules, is on the design page. A case meets the target of the baseline, a ratio of at most 3, when the upper end of that interval is at most 3. A case whose reference net time cannot be told from zero, whose floating net time is not above zero, or whose interval is wider than a stated bound is reported as unresolved, is never counted as met, and is judged on the raw ratio (the median of the case blocks over the median of the case blocks, the number of 0.11.0), which is printed beside the net ratio. The measurements are native, release builds only.

The method makes the number honest; it does not move the target. Computed from the 0.11.0 medians, with the floating floor then measured (9.21 ns per operation) and any reference floor between 0.4 and 1.1 ns, 43 of the 59 cases are above 3 on the raw ratio and 42 on the net ratio; only decimal_gda multiplication at 100 digits (3.03) changes side.

Machine and toolchain

The table describes the run of 0.11.0; every summary records its own machine and toolchain in meta, and the sections of the new measurements state theirs.

ItemValue
CPUApple M4, 10 logical cores (4 performance, 6 efficiency), 16 GiB
OSDarwin 27.2.1 (Darwin kernel 27.2.0)
PowerAC power at start and end of the run; no frequency pinning, no core pinning
Other loadthe runner waits for the other processes to use under 150% CPU (1.5 cores) before each timed side; at the start of each side they used 8% to 34% (122% once, before the floating side of one round)
MoonBitmoon 0.1.20261119 (738607b 2026-11-19), v0.10.22+124d61d05 (2026-11-19)
floating buildmoon test --release --target native; moon compiles the generated C with /usr/bin/cc -fwrapv -fno-strict-aliasing -ffp-contract=off -Wno-unused-value -O2 -DMOONBIT_ALLOCATOR=MOONBIT_ALLOCATOR_MIMALLOC (reference-counted memory management, mimalloc allocator)
C compiler of the harnessApple clang 21.0.0 (Xcode command line tools), flags -O2
MPFR4.2.2 (Homebrew bottle, thread-local storage on, no shared cache)
GMP6.3.0 (Homebrew bottle, built with clang -O2 -pedantic -march=armv8-a)
mpdecimal4.0.1 (Homebrew bottle)
Library revision4a052ed42f18, clean working tree
Run2026-11-20T07:43:31Z, just bench external run with the standard preset
Operand and reference filesSHA-256 e05e3284482dab5f and 7ee258b310849477 (seed 20261118)

What is timed

Each case is one operation at one precision with eight different operand sets read from the same file by both sides (inputs.txt, written by one seeded generator; checksums are in machine.json). One timed iteration is one pass over the eight sets, so a time per operation is the batch time divided by the iterations and by eight.

  • Binary. Operands and results have the case precision in bits. MPFR: mpfr_add, mpfr_mul, mpfr_div, mpfr_sqrt, mpfr_exp, mpfr_log, mpfr_sin with MPFR_RNDN. floating: the Binary methods add, mul, div, sqrt, exp, ln, sin on operands of that precision (round to nearest even, unbounded exponent range).
  • decimal_gda. Operands and results have the case digit count, rounding half even, exponent range ±999999. libmpdec: mpd_qadd, mpd_qmul, mpd_qdiv, mpd_qsqrt, mpd_qexp, mpd_qln with allcr = 1. floating: decimal_gda add, multiply, divide, sqrt, exp, ln in a context of that precision. libmpdec has no sin, so decimal_gda has six operations.
  • Included in the time. The library call itself, with whatever temporary storage it allocates internally. For floating this includes constructing the immutable result value. The loop around the call, and for floating Maremark’s per-iteration bookkeeping, are in the raw time and are removed in the net time by the null of the case (see the design page for what the null contains and what it cannot remove).
  • Excluded. Parsing operands, creating contexts, mpfr_t and mpd_t initialisation and result buffers (MPFR and libmpdec write into results allocated before timing), reading files, and printing. Process start-up and the first warm-up passes are outside the measured blocks.
  • Correctness. Before it is timed, every floating output is compared with the MPFR or libmpdec result for the same operand, as canonical text: the reference text (%Ra of MPFR, mpd_to_sci of libmpdec) and the text the library prints are each reduced by one small parser of the benchmark package (binary: sign, odd integer significand and exponent, or 0, -0, inf, nan; decimal: sign, coefficient with its trailing zeros, exponent), so the sign of zero, the decimal cohort, infinities and NaN are compared and no reader of the library stands between the reference and the verdict. A case checks its 8 distinct operand sets; the rounds and blocks repeat the same check, so the published run (59 cases, 7 rounds) makes 8 checks per case, not one per round (an earlier version of this page counted 427 comparisons that way). A run without a reference file (quick) is not validated and says so (EXTBENCH_NOT_VALIDATED, never EXTBENCH_FAILED=0). Both libraries round every result correctly (MPFR always; libmpdec with allcr = 1; floating by certified refinement), so at equal precision the results are identical and the ratio compares equal work. The reference side is another implementation (level A); the benchmark specs of the other bench packages compare the library with itself or with its own sibling and are timing harness checks, not validation.
  • Not trivially cached. The operands are 8 distinct random sets per case, every result is overwritten on the next pass, and neither library keeps a result cache. Both keep internal caches of constants such as π\pi and ln⁡2\ln 2 per precision; these are warm during timing on both sides (the warm-up passes fill them), so the numbers are steady-state rates, not cold-start costs.

Protocol

Both sides run the Maremark protocol with the same numbers: 3 warm-up passes and at least 5 ms of warm-up, batches calibrated to about 20 ms (at least one pass of eight operations), 3 exploratory pairs that are discarded and 12 confirmatory pairs. A pair is a block of the case and a block of its null, each with its own calibrated batch, back to back, the order alternating. The two sides alternate over 7 rounds in seeded AB/BA order, each round with its own shuffled case order, so every cell has 84 confirmatory pairs per side from 7 separate processes. The rules of the verdict (84 pairs, the width bound of 1.25 on the ratio interval, the 5% drift and order thresholds, the target of 3) are fixed in the method and written into the protocol block of every summary. Before each side starts, the runner waits until other processes use under 150% CPU. The slowest cells (elementary functions at 8192 bits and 1000 digits) take seconds per pass, so their batch is a single pass.

Configurations and results

The floating side is measured in two configurations of the native build, each published as its own summary and shown in its own section: native, with the native limb primitives where the build has them, and native-portable, with the portable path forced. The target has to be reached by the portable path too. It is also measured on two other runtimes, wasm and js, which are judged on the same net ratio to the native reference with two bounds: a case meets the target when the upper end of the interval is at most 5, is tolerated up to 10 and is not met above 10 (the native configurations have the one bound 3). The ratio of a runtime to native-portable is a diagnostic and has no verdict. Each runtime section counts its cases met, tolerated and not met. The configuration is chosen when the run starts (--target, --configuration NAME, --moon-env KEY=VALUE) and recorded in the summary. The tables of a configuration are generated by just bench external publish between the marker comments below and copied without editing.

Configuration native

Not measured yet with the net-ratio method. The first measurement with it is published with the next release; until then the results below are those of 0.11.0, measured with the raw method.

Configuration native-portable

Not measured yet with the net-ratio method.

Runtime wasm

wasm is expected within 5 times the native reference and may not exceed 10 times: a case meets the target when the upper end of the 95% interval of the net ratio of this library on wasm (under moonrun) to the native MPFR and libmpdec of the same run is at most 5, is tolerated when it is above 5 and at most 10, and is not met above 10, with the unresolved and borderline rules of the native sections applied to both bounds. That ratio mixes the library and the runtime, so the section also shows the ratio to the same case in native-portable, a diagnostic of the cost of the runtime with its interval and no verdict.

Not measured yet.

Runtime js

As for wasm: the same two bounds (5 and 10), and the ratio to native-portable as a diagnostic. The runtime is node; its versions are in the summary.

Not measured yet.

wasm-gc

Not measured, and not measurable at present: the benchmark driver uses moonbitlang/async, which has no wasm-gc runtime (its module initialiser casts between two struct types and the runtime rejects the module at validation; a reduced reproduction with that package alone shows it, and nothing is filed). See the design page.

Results of 0.11.0 (raw method)

These are the tables of the release 0.11.0, measured before the net-ratio method existed: the ratio is the median of the case blocks of floating over that of the reference, without a null, and the single floor known then was the 9.21 ns of the floating loop. They are kept as the record of that release (testdata/external_baseline/summary-0.11.0.json, schema v1) and are replaced by the sections above as the new measurements are published. The tables are the output of just bench external publish for that run, copied without editing.

Binary: floating binary against MPFR

Ratio floating / MPFR (median time, 95% bootstrap interval; above 1 means floating is slower)

op53 bits128 bits512 bits2048 bits8192 bits
add8.74 [8.66, 8.84]6.41 [6.32, 6.59]6.96 [6.90, 7.04]6.34 [6.23, 6.51]5.15 [5.11, 5.18]
mul7.58 [7.51, 7.65]3.98 [3.93, 4.07]3.79* [3.72, 3.82]3.93 [3.90, 3.96]3.92 [3.92, 3.93]
div7.94 [7.92, 8.06]5.88 [5.83, 5.93]3.19 [3.17, 3.24]3.70 [3.66, 3.73]4.76 [4.75, 4.77]
sqrt10.12 [9.99, 10.22]1.90 [1.90, 1.92]4.60 [4.56, 4.68]4.12 [4.06, 4.18]4.28 [4.24, 4.37]
exp3.09 [3.06, 3.13]2.52 [2.51, 2.54]2.50 [2.48, 2.52]5.23 [5.17, 5.29]2.99 [2.96, 3.02]
ln6.92 [6.89, 7.09]4.60 [4.55, 4.64]6.20 [6.16, 6.23]10.87 [10.80, 10.94]9.54 [9.45, 9.58]
sin8.84 [8.76, 8.93]7.70 [7.61, 7.76]7.26 [7.23, 7.31]10.13 [10.08, 10.22]5.24 [5.18, 5.26]

Median ns per operation, MPFR

op53 bits128 bits512 bits2048 bits8192 bits
add4.59 ns6 ns12.4 ns21.7 ns85.6 ns
mul5 ns10.1 ns32 ns231 ns2.13 us
div5.38 ns26.3 ns106 ns498 ns4 us
sqrt5.64 ns62.3 ns162 ns509 ns2.83 us
exp557 ns846 ns2.35 us16.8 us208 us
ln388 ns1.09 us3.41 us14.9 us116 us
sin496 ns792 ns2.22 us14.1 us197 us

Median ns per operation, floating

op53 bits128 bits512 bits2048 bits8192 bits
add40.1 ns38.5 ns86.2 ns138 ns441 ns
mul37.9 ns40 ns121 ns910 ns8.34 us
div42.8 ns154 ns340 ns1.84 us19 us
sqrt57.1 ns119 ns745 ns2.1 us12.1 us
exp1.72 us2.13 us5.89 us87.7 us619 us
ln2.69 us4.99 us21.2 us162 us1.11 ms
sin4.38 us6.1 us16.1 us143 us1.03 ms

Decimal GDA: floating decimal_gda against libmpdec

Ratio floating / libmpdec (median time, 95% bootstrap interval; above 1 means floating is slower)

op16 digits34 digits100 digits1000 digits
add3.63 [3.60, 3.67]11.39 [11.23, 11.55]8.71 [8.61, 8.83]6.01 [5.89, 6.13]
mul4.25 [4.20, 4.30]5.41 [5.27, 5.63]3.03 [3.00, 3.06]1.74 [1.72, 1.77]
div2.95 [2.90, 2.98]6.15 [6.09, 6.25]4.33 [4.28, 4.37]3.09 [3.07, 3.11]
sqrt5.31 [5.28, 5.35]4.27 [4.24, 4.31]2.77 [2.75, 2.78]2.12 [2.10, 2.13]
exp2.92 [2.88, 2.95]1.53 [1.52, 1.55]1.39 [1.38, 1.41]0.11 [0.11, 0.11]
ln1.28 [1.27, 1.29]0.96 [0.96, 0.98]1.17 [1.16, 1.18]0.28 [0.27, 0.28]

Median ns per operation, libmpdec

op16 digits34 digits100 digits1000 digits
add20 ns21.9 ns35.1 ns171 ns
mul19.4 ns48.7 ns136 ns9.05 us
div31.6 ns122 ns328 ns14.5 us
sqrt307 ns1.07 us4.03 us213 us
exp2.97 us7.97 us17.5 us4.69 ms
ln9.94 us18 us43.2 us5.24 ms

Median ns per operation, floating

op16 digits34 digits100 digits1000 digits
add72.5 ns249 ns306 ns1.03 us
mul82.6 ns264 ns413 ns15.7 us
div93.3 ns750 ns1.42 us44.8 us
sqrt1.63 us4.55 us11.2 us451 us
exp8.67 us12.2 us24.3 us523 us
ln12.7 us17.4 us50.4 us1.45 ms

Harness overhead of the floating side

casens per operation (loop and result store only)
binary/null/539.21 ns [9.15 ns, 9.26 ns]
decimal_gda/null/169.21 ns [9.14 ns, 9.32 ns]

Cells marked with an asterisk exceeded a dispersion threshold (CI half-width over 5% of the median, or round medians spread by over 10%): binary/mul/512.

What the numbers say

Everything below is read from the tables above; ratios are rounded and the intervals are in the tables.

floating is slower than the reference in 56 of the 59 cells and faster in three, all decimal_gda. Excluding those, the smallest ratio is 1.28 (decimal_gda ln at 16 digits) and the largest 11.4 (decimal_gda addition at 34 digits). Four cells are above 10: binary sqrt at 53 bits (10.1), binary ln and sin at 2048 bits (10.9 and 10.1), and decimal_gda addition at 34 digits (11.4). Where floating is faster, it is exp at 1000 digits (0.11, that is 9 times faster: 523 us against 4.69 ms), ln at 1000 digits (0.28, 3.6 times faster: 1.45 ms against 5.24 ms) and ln at 34 digits (0.96, a difference of 4%, with the interval [0.96, 0.98] below 1).

Basic binary arithmetic: roughly 3 to 9 times slower. Addition costs 5.2 to 8.7 times MPFR’s time at every precision, multiplication 3.8 to 7.6, division 3.2 to 7.9. The gap is widest at 53 bits, where MPFR needs 4.6 ns for an addition and floating 40.1 ns; about 9.2 ns of that is the harness (see the null row), the rest is allocation and normalisation of an immutable result. At 128 bits and above multiplication stays at 3.8 to 4.0 times (8192 bits: 8.34 us against 2.13 us).

Square root is not smooth in precision. The ratio is 10.1 at 53 bits, 1.9 at 128 bits, 4.6 at 512 bits and 4.1 to 4.3 at 2048 and 8192 bits. From 128 to 512 bits, 4 times the width, the time of floating grows from 119 ns to 745 ns (6.3 times) and MPFR’s from 62.3 ns to 162 ns (2.6 times).

Elementary functions: 2.5 to 11 times slower than MPFR in binary. exp is 2.5 to 5.2 times slower at every precision (3.1 at 53 bits, 5.2 at 2048 bits, 3.0 at 8192 bits), ln 4.6 to 10.9 times and sin 5.2 to 10.1 times. These three have their largest ratios at 2048 bits (5.2, 10.9, 10.1), not at 8192 bits (3.0, 9.5, 5.2); the cost is not a smooth function of the precision. Both libraries are correctly rounded, so the work is equal in specification but not in method. The slowest binary operations measured are ln and sin at 8192 bits (1.11 ms and 1.03 ms against 116 us and 197 us in MPFR).

decimal_gda: slower for the four basic operations, at par or faster for exp and ln from about 34 digits. Against libmpdec, addition is 3.6 to 11.4 times slower, multiplication 1.7 to 5.4, division 3.0 to 6.2 and square root 2.1 to 5.3. Multiplication, division and square root narrow towards the large size: at 1000 digits they are 1.7, 3.1 and 2.1 times libmpdec. exp is 2.9, 1.5 and 1.4 times slower at 16, 34 and 100 digits and 0.11 at 1000 digits; ln is 1.28, 0.96, 1.17 and 0.28. This comes from libmpdec’s side: from 100 to 1000 digits its exp time grows 268 times (17.5 us to 4.69 ms) and its ln time 121 times (43.2 us to 5.24 ms), against 21.5 times (24.3 us to 523 us) and 29 times (50.4 us to 1.45 ms) for floating. These are the measured times; the cause in libmpdec was not investigated here. For scale, against MPFR at binary sizes near 1000 decimal digits (2048 and 8192 bits), the binary floating exp is 5.2 and 3.0 times slower and ln 10.9 and 9.5 times slower, so the floating advantage over libmpdec at 1000 digits is not an advantage over a binary library of the same size class.

Harness overhead. The null rows show that the timed loop of the floating side costs 9.2 ns per operation with the arithmetic removed. That is 23% of the 40.1 ns of a 53-bit addition and 16% of the 57.1 ns of a 53-bit square root, about 1% of 1 us and less above it; it is not subtracted in these tables. The loop of the C side was not measured in that run.

Dispersion. Within a process the 20 ms batches vary by under 3.1% (largest median absolute deviation 1.5% for floating and 3.1% for the references). Between the seven rounds the medians of one cell spread by at most 6.0% for floating and 25.3% for the references (the reference side of binary/mul/512, the one cell marked in the table); the bootstrap intervals therefore cover whole-process variation, and the half-widths of the medians are at most 1.7% for floating and 3.1% for the references, and at most 3.3% for a ratio.

Repeatability. The run was repeated once on the same commit 4a052ed with a different round-order seed. The run published here is the first one, with the quieter machine: the other processes used 8% to 34% of the CPU before the timed sides (once 122%), against 26% to 110% in the second run. Over the 59 cases the medians of floating moved by 0.43% in the median and 2.1% at most, and the ratios by 0.72% in the median. Two ratios moved by more than 3%: binary/mul/8192 (3.92 to 3.41, entirely on the MPFR side, which was 15% slower in the second run) and decimal_gda/mul/34 (5.41 to 5.59). Neither run had a validation failure. The second run is not published.

Follow-ups (not fixed here)

No profile was taken for this run, so the list is read from the ratios only and names where the largest gaps are, not their cause.

  • Small binary cases. At 53 bits floating takes 38 to 57 ns for add, mul, div and sqrt, 7.6 to 10.1 times MPFR, with 9.2 ns of the harness included; sqrt at 53 bits (10.1) stands out against 1.9 at 128 bits.
  • ln and sin at 2048 bits and 8192 bits. Ratios of 10.9 and 10.1 at 2048 bits and 9.5 at 8192 bits for ln, the largest elementary ratios; exp is at 2.5 to 5.2 at all sizes.
  • sqrt at 512 bits. 4.6 times MPFR against 1.9 at 128 bits.
  • decimal_gda addition at 34 and 100 digits. 11.4 and 8.7 times, against 3.6 at 16 digits; the largest basic-operation ratios of the decimal side.

What is not measured

  • Other targets. JavaScript, WebAssembly and LLVM builds are not measured; the C libraries have no counterpart there.
  • Other machines and compilers. One Apple M4 laptop on AC power, with no frequency or core pinning and some background desktop load; absolute times will differ on other hardware, and ratios shift with the memory system and the CPU’s multiplier and SIMD units.
  • Tuned library builds. The MPFR and GMP in use are Homebrew bottles built with -O2 -march=armv8-a; a GMP configured for the exact CPU, or a libmpdec with other build options, can be faster.
  • Large and special arguments. Elementary functions are timed on well-conditioned arguments of modest magnitude; argument reduction of huge arguments, arguments near zeros and singularities, subnormal results, overflow, and exceptional values are not timed.
  • Cold start. Warm caches only; the cost of the first call at a precision is excluded.
  • Other operations. fma, pow, hypot, cos, tan, the hyperbolic and inverse functions, remainders, conversions, and parsing and printing are not compared. Interval (interval) arithmetic has no counterpart in MPFR and is not compared (MPFI is not part of this baseline).
  • Memory and threads. Peak memory and multi-threaded behaviour are not measured.
  • Other rounding modes. Only round to nearest even.

Reproduce

just bench external run --configuration native
just bench external publish

run writes the inputs, the reference results, the raw rounds, the summary and the samples under .tmp/external; publish copies the compact summary to testdata/external_baseline/summary-VERSION-CONFIGURATION.json, the samples (the pairs of every case) to samples-VERSION-CONFIGURATION.json.gz, the tables to summary-CONFIGURATION.md, and regenerates the tables of that configuration on this page. The raw JSONL (about 12 MB) is not committed; its checksums and the checksums of the operand and reference files are in the published summary. just bench external recompute SUMMARY SAMPLES recomputes a summary from its samples; just bench external compare OLD NEW compares two summaries (net ratios when both are resolved, raw ratios otherwise) and just bench external table OLD NEW... writes the table of a run beside a release, as Markdown and CSV, one section per configuration; see the tutorial for the commands and the API page for the benchmark cases.