11#! /bin/bash
22
33# Benchmark Results Summary Script
4- # 用于从 BenchmarkDotNet JSON 结果中提取关键性能指标
4+ # 直接从 BenchmarkDotNet 生成的 Markdown 报告中提取结果
55
66echo " # Benchmark Results Summary"
77echo " "
@@ -19,59 +19,24 @@ for fw in "${frameworks[@]}"; do
1919 echo " ### Framework: ${fw} "
2020 echo " "
2121
22- # 查找 JSON 结果文件
23- json_files =$( find " $result_dir " -name " *.json " -type f 2> /dev/null)
22+ # 查找 Markdown 报告文件
23+ md_files =$( find " $result_dir " -name " *-report-github.md " -type f 2> /dev/null)
2424
25- if [ -n " $json_files " ]; then
26- echo " Found benchmark results:"
27-
28- for json_file in $json_files ; do
29- benchmark_name=$( basename " $json_file " .json)
30- echo " "
25+ if [ -n " $md_files " ]; then
26+ for md_file in $md_files ; do
27+ benchmark_name=$( basename " $md_file " -report-github.md)
3128 echo " #### $benchmark_name "
29+ echo " "
3230
33- # 使用 jq 提取完整的关键指标(如果可用)
34- if command -v jq & > /dev/null; then
35- echo " | Method | Mean (μs) | Error (μs) | StdDev (μs) | Ratio | Gen0 | Allocated (KB) | Alloc Ratio |"
36- echo " |--------|-----------|------------|-------------|-------|------|----------------|-------------|"
37-
38- # 提取详细数据,转换单位
39- jq -r ' .Benchmarks[] |
40- "| \(.Method) | \(
41- if .Statistics.Mean then
42- (.Statistics.Mean / 1000 | . * 100 | round / 100)
43- else "N/A" end
44- ) | \(
45- if .Statistics.StandardError then
46- (.Statistics.StandardError / 1000 | . * 100 | round / 100)
47- else "N/A" end
48- ) | \(
49- if .Statistics.StandardDeviation then
50- (.Statistics.StandardDeviation / 1000 | . * 100 | round / 100)
51- else "N/A" end
52- ) | \(
53- if .Ratio then
54- (.Ratio | . * 100 | round / 100)
55- else "N/A" end
56- ) | \(
57- .Memory.Gen0Collections // "0"
58- ) | \(
59- if .Memory.BytesAllocatedPerOperation then
60- (.Memory.BytesAllocatedPerOperation / 1024 | . * 100 | round / 100)
61- else "N/A" end
62- ) | \(
63- if .Memory.AllocRatio then
64- (.Memory.AllocRatio | . * 100 | round / 100)
65- else "N/A" end
66- ) |"' " $json_file " 2> /dev/null || echo " Unable to parse JSON"
67- else
68- echo " ⚠️ jq not available, showing file location: $json_file "
69- echo " "
70- echo " Please install jq to see detailed performance metrics."
71- fi
31+ # 直接提取 Markdown 表格(从表头到空行)
32+ # 查找包含 "| Method" 的行,然后提取完整表格
33+ awk ' /\| Method.*\|/ {found=1} found {print} /^$/ && found {exit}' " $md_file " |
34+ grep -v " ^$" || echo " No table found in $md_file "
35+
36+ echo " "
7237 done
7338 else
74- echo " No JSON results found in $result_dir "
39+ echo " No Markdown reports found in $result_dir "
7540 fi
7641
7742 echo " "
8550
8651echo " ## Performance Metrics Explanation"
8752echo " "
88- echo " - **Mean**: Average execution time in microseconds (μs) "
53+ echo " - **Mean**: Average execution time"
8954echo " - **Error**: Half of 99.9% confidence interval"
9055echo " - **StdDev**: Standard deviation of all measurements"
91- echo " - **Ratio**: Mean of current method divided by baseline mean"
56+ echo " - **Ratio**: Performance ratio compared to baseline (lower is better for baseline)"
57+ echo " - **RatioSD**: Standard deviation of the Ratio"
9258echo " - **Gen0**: GC Generation 0 collections per 1000 operations"
93- echo " - **Allocated**: Total memory allocated per operation in kilobytes (KB) "
94- echo " - **Alloc Ratio**: Allocated memory ratio compared to baseline"
59+ echo " - **Allocated**: Total memory allocated per operation"
60+ echo " - **Alloc Ratio**: Memory allocation ratio compared to baseline"
9561echo " "
9662echo " ## Notes"
9763echo " "
64+ echo " - **Baseline** method (marked with 🏆 or Ratio=1.00) is the reference point"
9865echo " - Lower values are better for Mean, Error, StdDev, and Allocated"
99- echo " - Ratio of 1.00 means equal performance to baseline (typically the first method) "
100- echo " - Download the artifact 'benchmark-results' for detailed reports and raw JSON data"
66+ echo " - Ratio > 1.00 means slower/more memory than baseline"
67+ echo " - Download the artifact 'benchmark-results' for detailed reports and raw data"
10168echo " "
0 commit comments