(system_info, results, sizes, output_dir, plot_prefix)
| 279 | |
| 280 | |
| 281 | def write_report(system_info, results, sizes, output_dir, plot_prefix): |
| 282 | report = [ |
| 283 | "# Rust Benchmark Performance Report\n\n", |
| 284 | f"_Generated on {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}_\n\n", |
| 285 | "## How to Generate This Report\n\n", |
| 286 | "```bash\n", |
| 287 | "cd benchmarks/rust\n", |
| 288 | "cargo bench --bench serialization_bench 2>&1 | tee results/cargo_bench.log\n", |
| 289 | "cargo run --release --bin fory_profiler -- --print-all-serialized-sizes | tee results/serialized_sizes.txt\n", |
| 290 | "python benchmark_report.py --log-file results/cargo_bench.log --size-file results/serialized_sizes.txt --output-dir results\n", |
| 291 | "```\n\n", |
| 292 | "## Benchmark Plot\n\n", |
| 293 | "The plot shows throughput (ops/sec); higher is better.\n\n", |
| 294 | f"\n\n", |
| 295 | "## Hardware & OS Info\n\n", |
| 296 | "| Key | Value |\n", |
| 297 | "|-----|-------|\n", |
| 298 | ] |
| 299 | |
| 300 | for key, value in system_info.items(): |
| 301 | report.append(f"| {key} | {value} |\n") |
| 302 | |
| 303 | report.append("\n## Benchmark Results\n\n") |
| 304 | report.append("### Timing Results (nanoseconds)\n\n") |
| 305 | report.append( |
| 306 | "| Datatype | Operation | fory (ns) | protobuf (ns) | msgpack (ns) | Fastest |\n" |
| 307 | ) |
| 308 | report.append( |
| 309 | "|----------|-----------|-----------|---------------|--------------|---------|\n" |
| 310 | ) |
| 311 | |
| 312 | for datatype in DATATYPE_ORDER: |
| 313 | if datatype not in results: |
| 314 | continue |
| 315 | for operation in OPERATIONS: |
| 316 | times = { |
| 317 | serializer: results[datatype][operation].get(serializer, 0) |
| 318 | for serializer in SERIALIZER_ORDER |
| 319 | } |
| 320 | positive = {name: value for name, value in times.items() if value > 0} |
| 321 | fastest = min(positive, key=positive.get) if positive else "N/A" |
| 322 | report.append( |
| 323 | "| " |
| 324 | + f"{datatype_title(datatype)} | {operation.capitalize()} | " |
| 325 | + " | ".join( |
| 326 | f"{times[serializer]:.1f}" if times[serializer] > 0 else "N/A" |
| 327 | for serializer in SERIALIZER_ORDER |
| 328 | ) |
| 329 | + f" | {fastest} |\n" |
| 330 | ) |
| 331 | |
| 332 | report.append("\n### Throughput Results (ops/sec)\n\n") |
| 333 | report.append( |
| 334 | "| Datatype | Operation | fory TPS | protobuf TPS | msgpack TPS | Fastest |\n" |
| 335 | ) |
| 336 | report.append( |
| 337 | "|----------|-----------|----------|--------------|-------------|---------|\n" |
| 338 | ) |
no test coverage detected