Skip to content
WARNING

You are viewing the docs for an older major version of bon (v1).

Click here to view the docs for the latest version (v2).

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 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: 5.0784ns
builder: 5.0481ns
args_10_alloc10 args of primitive and heap-allocated typesInstructions diffregular: 86.090ns
builder: 86.790ns
args_2020 args of primitive typesOrdering diffregular: 37.381ns
builder: 37.623ns

High-precision statistics

BenchmarkInstructions countL1 accessesL2 accessesRAM accesses
args_3regular: 106
builder: 106
regular: 136
builder: 136
regular: 2
builder: 2
regular: 4
builder: 4
args_5regular: 124
builder: 124
regular: 161
builder: 161
regular: 1
builder: 1
regular: 9
builder: 9
args_10regular: 281
builder: 281
regular: 381
builder: 380
regular: 2
builder: 2
regular: 19
builder: 20
args_10_structsregular: 73
builder: 73
regular: 108
builder: 108
regular: 2
builder: 2
regular: 10
builder: 10
args_10_allocregular: 2025
builder: 2026
regular: 2823
builder: 2823
regular: 3
builder: 2
regular: 35
builder: 35
args_20regular: 554
builder: 554
regular: 768
builder: 769
regular: 3
builder: 3
regular: 34
builder: 33

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.