This directory orchestrates two independent Rust benchmark packages:
xlang/ compares Apache Fory, Protocol Buffers, and MessagePack with the shared models defined by benchmarks/proto/bench.proto.local/ owns Rust-local buffer and threading benchmarks plus external-type serialization comparisons.Neither package depends on the other, so building a local benchmark does not compile xlang models or serializer monomorphizations.
The xlang package generates Rust code from the shared schema and requires a protoc executable on PATH, or the PROTOC environment variable set to an existing executable. The local package does not require protoc.
Run the complete Rust benchmark pipeline:
cd benchmarks/rust ./run.sh
./run.sh --help Options: --data <struct|sample|mediacontent|structlist|samplelist|mediacontentlist> Filter benchmark by data type --serializer <fory|protobuf|msgpack> Filter benchmark by serializer --filter <regex> Custom criterion filter --no-report Skip Python report generation --no-copy-docs Skip copying the report into docs/benchmarks/rust
Examples:
# Run only NumericStruct benchmarks ./run.sh --data struct # Run only Protobuf benchmarks ./run.sh --serializer protobuf # Run only Sample and MediaContent benchmarks for Protobuf ./run.sh --data sample,mediacontent --serializer protobuf
Set FORY_BENCH_SCHEMA_MISMATCH=1 to run the Fory-only compatible-read schema-mismatch mode. This mode is off by default. When enabled, run with --serializer fory; protobuf and MessagePack benchmark modes fail with a configuration error. Fory serialization uses the normal v1 benchmark structs, and Fory deserialization uses v2 structs registered with the same Fory type IDs where one int32 field is widened to int64.
| Benchmark case | Description |
|---|---|
NumericStruct | Numeric struct with 12 int32 fields |
Sample | Mixed primitive and array payload matching the shared benchmark schema |
MediaContent | Media and image payload matching the Java/C++ benchmark data |
NumericStructList | List of shared NumericStruct payloads |
SampleList | List of shared Sample payloads |
MediaContentList | List of shared MediaContent payloads |
The local package's separate external_type_bench Criterion target contains Rust-local external-type serialization comparisons. Its package boundary preserves the xlang serialization_bench binary, dependency graph, and measurement shape. Each comparison has self_serialize, selected_serialize, self_deserialize, and selected_deserialize lanes. The self lane uses an equivalent self-provided Rust target. The selected lane uses the external structural serializer, manual serializer, carrier serializer, or registered external target named by the case. Setup verifies byte equality before measuring the pair.
The matrix covers:
Vec<i32>, Vec<u8>, and nested primitive Vec composition;dyn Any plus arbitrary registered application traits.Run one comparison case by its Criterion group name:
cargo bench --manifest-path local/Cargo.toml --bench external_type_bench -- carrier_map_nested cargo bench --manifest-path local/Cargo.toml --bench external_type_bench -- external_command_compatible cargo bench --manifest-path local/Cargo.toml --bench external_type_bench -- dynamic_trait_arc
The Rust xlang package uses the shared protobuf definition at benchmarks/proto/bench.proto, the same benchmark schema used by the C++ benchmark suite.
Run Criterion benchmarks:
cd benchmarks/rust cargo bench --manifest-path xlang/Cargo.toml --bench serialization_bench cargo bench --manifest-path local/Cargo.toml --bench external_type_bench
Print serialized sizes:
cd benchmarks/rust cargo run --release --manifest-path xlang/Cargo.toml --bin fory_profiler -- --print-all-serialized-sizes
Build either package independently:
cd benchmarks/rust cargo check --manifest-path xlang/Cargo.toml --all-targets cargo check --manifest-path local/Cargo.toml --all-targets
Generate the markdown report manually:
cd benchmarks/rust cargo bench --manifest-path xlang/Cargo.toml --bench serialization_bench 2>&1 | tee results/cargo_bench.log cargo bench --manifest-path local/Cargo.toml --bench external_type_bench 2>&1 | tee -a results/cargo_bench.log cargo run --release --manifest-path xlang/Cargo.toml --bin fory_profiler -- --print-all-serialized-sizes | tee results/serialized_sizes.txt python benchmark_report.py --log-file results/cargo_bench.log --size-file results/serialized_sizes.txt --output-dir results
When external-type comparison cases are present in the Criterion log, the report adds a table with self-provided and selected timings and their percentage delta. The existing cross-library plot and tables remain unchanged.
The report generator writes:
results/README.mdresults/throughput.png