This benchmark compares serialization and deserialization performance between Apache Fory, Protocol Buffers, and MessagePack in Swift.
swift/Sources/Fory)apple/swift-protobufFlight-School/MessagePack| Data Type | Description |
|---|---|
| Struct | Simple struct with 8 int32 fields |
| Sample | Complex struct with primitives and array fields |
| MediaContent | Nested object graph with strings, enums, and ids |
| StructList | List of Struct entries |
| SampleList | List of Sample entries |
| MediaContentList | List of MediaContent entries |
Benchmark data is aligned with benchmarks/cpp_benchmark for cross-language comparison.
cd benchmarks/swift ./run.sh
./run.sh --help
Supported flags:
--data <struct|sample|mediacontent|structlist|samplelist|mediacontentlist>--serializer <fory|protobuf|msgpack>--duration <seconds>--no-reportExamples:
# Run only Struct benchmarks ./run.sh --data struct # Run only protobuf benchmarks ./run.sh --serializer protobuf # Run a single serializer and datatype ./run.sh --data sample --serializer msgpack --duration 5 # Skip report generation ./run.sh --no-report
# Build benchmark swift build -c release # Run benchmark executable swift run -c release swift-benchmark --duration 3 --output results/benchmark_results.json # Generate markdown report and plot python3 benchmark_report.py --json-file results/benchmark_results.json --output-dir results
After running ./run.sh, the following files are generated in benchmarks/swift/results/:
benchmark_results.json: raw benchmark metrics and serialized-size comparisonthroughput.png: throughput comparison plotREPORT.md: markdown report with hardware/runtime info and result tablesSources/SwiftBenchmarkProto/bench.pb.swift from Sources/SwiftBenchmarkProto/bench.proto.protoc \ --plugin=protoc-gen-swift=.build/arm64-apple-macosx/release/protoc-gen-swift-tool \ --swift_opt=Visibility=Public \ --swift_out=Sources/SwiftBenchmarkProto \ --proto_path=Sources/SwiftBenchmarkProto \ Sources/SwiftBenchmarkProto/bench.proto