@@ -83,36 +83,50 @@ jobs:
8383 exit 0
8484 fi
8585
86- # Parse Criterion output: lines like "time: [X.XX µs X.XX µs X.XX µs]"
87- ROWS=""
88- CURRENT_BENCH=""
89- while IFS= read -r line; do
90- # Detect benchmark name (lines that don't start with whitespace and aren't empty)
91- if echo "$line" | grep -qE '^[a-zA-Z].*/{0,1}[a-zA-Z]'; then
92- CURRENT_BENCH=$(echo "$line" | sed 's|/| / |g' | xargs)
93- fi
94- # Detect timing line
95- if echo "$line" | grep -qE 'time:.*\['; then
96- # Extract the middle (median) value
97- MEDIAN=$(echo "$line" | grep -oE '\[[^]]+\]' | head -1 | sed 's/\[//' | sed 's/\]//' | awk '{print $3, $4}')
98- if [ -n "$CURRENT_BENCH" ] && [ -n "$MEDIAN" ]; then
99- ROWS="$ROWS\n| \`$CURRENT_BENCH\` | $MEDIAN |"
100- fi
101- fi
102- done < bench_output.txt
86+ # Parse using Perl: handles multi-line Criterion output correctly.
87+ # Criterion format:
88+ # Line 1 (name line): "bench_name/param time: [low median high]"
89+ # OR split across two lines:
90+ # Line 1: "bench_name/param"
91+ # Line 2: " time: [low median high]"
92+ # Strategy: collect name from lines that look like bench names (no leading space,
93+ # contain word chars + optional /param), then extract median from the time: [...] line.
94+ ROWS=$(perl -ne '
95+ # Match standalone benchmark name line (no leading whitespace, ends with word/number)
96+ if (/^([a-zA-Z]\S+(?:\/\S+)?)\s*$/) {
97+ $name = $1;
98+ }
99+ # Match inline: "bench_name/param time: [low median high]"
100+ elsif (/^([a-zA-Z]\S+(?:\/\S+)?)\s+time:\s+\[([^\]]+)\]/) {
101+ $name = $1;
102+ my @vals = split(/\s+/, $2);
103+ # median is index 2 (0=low_val, 1=low_unit, 2=med_val, 3=med_unit)
104+ my $median = "$vals[2] $vals[3]";
105+ $median =~ s/^\s+|\s+$//g;
106+ print "| `$name` | $median |\n";
107+ $name = "";
108+ }
109+ # Match timing on its own line (after name was set)
110+ elsif ($name && /^\s+time:\s+\[([^\]]+)\]/) {
111+ my @vals = split(/\s+/, $1);
112+ my $median = "$vals[2] $vals[3]";
113+ $median =~ s/^\s+|\s+$//g;
114+ print "| `$name` | $median |\n";
115+ $name = "";
116+ }
117+ ' bench_output.txt)
103118
104119 # Build the full block
105120 {
106121 echo "<!-- BENCHMARK_RESULTS_START -->"
107122 echo "> 🤖 Auto-updated by CI on **${DATE}** — [View run](${RUN_URL})"
108123 echo ""
109124 if [ -n "$ROWS" ]; then
110- echo "| Benchmark | Tempo (mediana) |"
111- echo "|-----------|----------------|"
112- printf "%b" "$ROWS"
113- echo ""
125+ echo "| Benchmark | Mediana |"
126+ echo "|-----------|--------|"
127+ echo "$ROWS"
114128 else
115- echo "*Nenhum resultado parseados — verifique os [artefatos do run](${RUN_URL}).*"
129+ echo "*Nenhum resultado parseado — verifique os [artefatos do run](${RUN_URL}).*"
116130 fi
117131 echo ""
118132 echo "<!-- BENCHMARK_RESULTS_END -->"
0 commit comments