tree: dbbd13bb0ca38a2eb16d0be174de92c61a4574a0 [path history] [tgz]
  1. .gitignore
  2. benchmark_report.py
  3. BenchmarkModels.cs
  4. BenchmarkSerializers.cs
  5. Fory.CSharpBenchmark.csproj
  6. Program.cs
  7. README.md
  8. run.sh
benchmarks/csharp/README.md

Fory C# Benchmark

This benchmark compares Apache Fory C#, protobuf-net, and MessagePack-CSharp.

Serializer setup used in this benchmark:

  • fory: Fory.Builder().Compatible(true).Build()
  • protobuf: protobuf-net runtime serializer
  • msgpack: MessagePackSerializer.Typeless with TypelessContractlessStandardResolver

Prerequisites

  • .NET SDK 8.0+
  • Python 3.8+

Quick Start

cd benchmarks/csharp
./run.sh

This runs all benchmark cases and generates:

  • build/benchmark_results.json
  • report/README.md
  • report/throughput.png and per-datatype throughput plots (for example report/struct.png)

Run Options

./run.sh --help

Options:
  --data <struct|sample|mediacontent|structlist|samplelist|mediacontentlist>
  --serializer <fory|protobuf|msgpack>
  --duration <seconds>
  --warmup <seconds>

Examples:

# Run only struct benchmarks
./run.sh --data struct

# Run only Fory benchmarks
./run.sh --serializer fory

# Use longer runs for stable numbers
./run.sh --duration 10 --warmup 2

Benchmark Cases

  • struct: 8-field integer object
  • sample: mixed primitive fields and arrays
  • mediacontent: nested object with list fields
  • structlist: list of struct payloads
  • samplelist: list of sample payloads
  • mediacontentlist: list of media content payloads

Each case benchmarks:

  • serialize throughput
  • deserialize throughput

Results

Latest run (Darwin arm64, .NET 8.0.24, --duration 2 --warmup 0.5):

SerializerMean ops/sec across all cases
fory2,032,057
protobuf1,940,328
msgpack1,901,489

Per-case winners vary by payload and operation. The full breakdown is generated at:

  • benchmarks/csharp/build/benchmark_results.json
  • benchmarks/csharp/report/README.md
  • benchmarks/csharp/report/*.png