tree: 1d38ca3abaf65929cedec033972cb2f951154af9 [path history] [tgz]
  1. protocol_benchmark.rb
  2. README.md
test/rb/benchmarks/README.md

Ruby Protocol Benchmarks

This directory holds a small harness for quick Ruby protocol benchmarks. Use it to spot read and write regressions in tree.

Quick Start

Run the script with plain ruby from the repo root.

ruby test/rb/benchmarks/protocol_benchmark.rb

This runs the full benchmark set:

  • Ruby binary
  • Ruby compact
  • Ruby JSON
  • Header binary
  • Header compact
  • Header zlib
  • C binary, if thrift_native.so loads

Options

Use flags or env vars to tune a run.

ruby test/rb/benchmarks/protocol_benchmark.rb --large-runs 1 --small-runs 10000
  • --json
  • THRIFT_BENCHMARK_LARGE_RUNS
  • THRIFT_BENCHMARK_SMALL_RUNS
  • THRIFT_BENCHMARK_SKIP_NATIVE=1
  • THRIFT_BENCHMARK_SCENARIOS
ruby test/rb/benchmarks/protocol_benchmark.rb --json > benchmark.json

[!NOTE] --json keeps the warm-up pass, but only prints measured results.

[!TIP] Set THRIFT_BENCHMARK_SKIP_NATIVE=1 to force a pure-Ruby run.

Scenario IDs

Use --scenarios or THRIFT_BENCHMARK_SCENARIOS to run only part of the matrix.

ruby test/rb/benchmarks/protocol_benchmark.rb --scenarios rb-bin-write-large,rb-json-read-large,hdr-zlib-read-small

Each ID has four parts:

  • family: rb, c, or hdr
  • protocol: bin, cmp, json, or zlib
  • operation: write or read
  • size: large or small

Full Table

IDFamilyProtocolOperationSize
rb-bin-write-largeRubybinarywritelarge
rb-bin-read-largeRubybinaryreadlarge
c-bin-write-largeC nativebinarywritelarge
c-bin-read-largeC nativebinaryreadlarge
rb-cmp-write-largeRubycompactwritelarge
rb-cmp-read-largeRubycompactreadlarge
rb-json-write-largeRubyJSONwritelarge
rb-json-read-largeRubyJSONreadlarge
rb-bin-write-smallRubybinarywritesmall
rb-bin-read-smallRubybinaryreadsmall
c-bin-write-smallC nativebinarywritesmall
c-bin-read-smallC nativebinaryreadsmall
rb-cmp-write-smallRubycompactwritesmall
rb-cmp-read-smallRubycompactreadsmall
rb-json-write-smallRubyJSONwritesmall
rb-json-read-smallRubyJSONreadsmall
hdr-bin-write-smallHeaderbinarywritesmall
hdr-bin-read-smallHeaderbinaryreadsmall
hdr-cmp-write-smallHeadercompactwritesmall
hdr-cmp-read-smallHeadercompactreadsmall
hdr-zlib-write-smallHeaderzlibwritesmall
hdr-zlib-read-smallHeaderzlibreadsmall

[!NOTE] Native-only IDs fail if thrift_native.so is not available.

Reference

What It Measures

  • Large jobs serialize and deserialize one nested Nested4 payload by default.
  • Small jobs serialize and deserialize many OneOfEach payloads.
  • Read jobs use payloads built before timing so they measure read cost, not payload construction.
  • Header jobs flush after each struct so reads benchmark framed messages, not a buffered write that was never emitted.

Files

  • protocol_benchmark.rb: benchmark harness and scenario definitions
  • ../fixtures/structs.rb: sample structs used by the benchmark

Notes

This harness is for quick in-tree checks. Use --json if you want structured output for scripts, result diffs, or branch comparisons. Run it more than once if you want a wider sample.