Skip to content

Benchmarks

#[builder] generates code that is easily optimizable by the compiler. This has been tested by the benchmarks below. The benchmarks compare regular positional function call syntax and builder syntax for functions annotated with #[builder].

In many cases rustc generates the same assembly code for the builder syntax as it would for a regular function call. Even when the generated assembly differs, the performance differences are negligible.

TIP

Don't take these microbenchmarks for granted. Do your own performance measurements in your application in real conditions. Feel free to open an issue if you find performance problems in bon.

Wallclock statistics

BenchmarkDescriptionAssembly outputRun time
args_33 args of primitive typesEqualregular: 6.6536ns
builder: 6.6494ns
args_55 args of primitive typesEqualregular: 7.9592ns
builder: 7.9731ns
args_1010 args of primitive typesOrdering diffregular: 18.082ns
builder: 18.217ns
args_10_structs10 args of primitive types and structsEqualregular: 9.2492ns
builder: 9.2325ns
args_10_alloc10 args of primitive and heap-allocated typesInstructions diffregular: 86.090ns
builder: 86.790ns
args_2020 args of primitive typesOrdering diffregular: 36.121ns
builder: 36.298ns

High-precision statistics

BenchmarkInstructions countL1 accessesL2 accessesRAM accesses
args_3regular: 108
builder: 108
regular: 138
builder: 138
regular: 2
builder: 2
regular: 4
builder: 4
args_5regular: 126
builder: 126
regular: 161
builder: 161
regular: 2
builder: 2
regular: 10
builder: 10
args_10regular: 281
builder: 281
regular: 381
builder: 380
regular: 2
builder: 2
regular: 19
builder: 20
args_10_structsregular: 75
builder: 75
regular: 106
builder: 106
regular: 4
builder: 4
regular: 12
builder: 12
args_10_allocregular: 2028
builder: 2027
regular: 2824
builder: 2824
regular: 3
builder: 2
regular: 36
builder: 36
args_20regular: 556
builder: 556
regular: 767
builder: 767
regular: 4
builder: 4
regular: 36
builder: 36

Conditions

The code was compiled with opt-level = 3 and debug = 0.

Hardware

The benchmarks were run on a dedicated root server AX51-NVMe on Hetzner.

  • OS: Ubuntu 22.04.4 (Linux 5.15.0-76-generic)
  • CPU: AMD Ryzen 7 3700X 8-Core Processor (x86_64)
  • RAM: 62.8 GiB

References

The source code of the benchmarks is available here.