Skip to content

Commit ecd3029

Browse files
committed
feat: fix benchzribe issues and add automated README updates
- Fix missing go.sum dependencies with go mod tidy - Remove dead code in main.go by refactoring to use existing handlers - Fix graph generation bug (missing fmt import and data["ops"] reference) - Add new GitHub Actions workflow for automated README updates - Update README to reflect working graph functionality - Add test script for CI flow verification - Generate real benchmark results and interactive graphs Fixes: - Graph generation now works correctly with proper data handling - CI workflow automatically updates README with latest benchmark results - All tests pass and code builds successfully
1 parent aff70b3 commit ecd3029

8 files changed

Lines changed: 191 additions & 47 deletions

File tree

.github/workflows/bench.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ jobs:
4242
cd mockapi
4343
go test ./internal/benchmarks -bench=. -benchmem > ../bench.out
4444
cd ..
45+
echo "Generated benchmark results:"
46+
cat bench.out
4547
4648
- name: Store benchmark result
4749
uses: benchmark-action/github-action-benchmark@v1
@@ -63,10 +65,14 @@ jobs:
6365
- name: Update README
6466
run: |
6567
./benchzribe run
68+
echo "README updated, checking changes:"
69+
git status
6670
6771
- name: Generate graph
6872
run: |
6973
./benchzribe graph
74+
echo "Graph generated, checking files:"
75+
ls -la *.html *.out
7076
7177
- name: Upload artifacts
7278
uses: actions/upload-artifact@v4
@@ -77,7 +83,20 @@ jobs:
7783
benchmark-graph.html
7884
retention-days: 90
7985

86+
- name: Check for changes
87+
id: verify-changed-files
88+
run: |
89+
if git diff --quiet; then
90+
echo "No changes detected"
91+
echo "has_changes=false" >> $GITHUB_OUTPUT
92+
else
93+
echo "Changes detected:"
94+
git diff --name-only
95+
echo "has_changes=true" >> $GITHUB_OUTPUT
96+
fi
97+
8098
- name: Commit changes
99+
if: steps.verify-changed-files.outputs.has_changes == 'true'
81100
uses: stefanzweifel/git-auto-commit-action@v5
82101
with:
83102
commit_message: "chore: update benchmark results [skip ci]"
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
name: Update Benchmark Results
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
paths:
7+
- 'internal/**'
8+
- 'cmd/**'
9+
- 'mockapi/**'
10+
- 'go.mod'
11+
- 'go.sum'
12+
workflow_dispatch: # Allow manual triggering
13+
14+
permissions:
15+
contents: write
16+
17+
jobs:
18+
update-benchmarks:
19+
name: Update README with Latest Benchmarks
20+
runs-on: ubuntu-latest
21+
steps:
22+
- name: Checkout code
23+
uses: actions/checkout@v4
24+
with:
25+
fetch-depth: 0
26+
token: ${{ secrets.GITHUB_TOKEN }}
27+
28+
- name: Set up Go
29+
uses: actions/setup-go@v5
30+
with:
31+
go-version: '1.21'
32+
cache: true
33+
34+
- name: Install dependencies
35+
run: |
36+
go mod download
37+
go mod tidy
38+
39+
- name: Build benchzribe
40+
run: |
41+
go build -v -o benchzribe ./cmd/benchzribe
42+
43+
- name: Run benchmarks
44+
run: |
45+
echo "Running benchmarks..."
46+
cd mockapi
47+
go test ./internal/benchmarks -bench=. -benchmem > ../bench.out
48+
cd ..
49+
echo "Benchmark results generated:"
50+
cat bench.out
51+
52+
- name: Update README with benchmark results
53+
run: |
54+
echo "Updating README..."
55+
./benchzribe run
56+
echo "README update completed"
57+
58+
- name: Generate benchmark graph
59+
run: |
60+
echo "Generating graph..."
61+
./benchzribe graph
62+
echo "Graph generated: benchmark-graph.html"
63+
64+
- name: Check for changes
65+
id: check_changes
66+
run: |
67+
git add -A
68+
if git diff --staged --quiet; then
69+
echo "No changes to commit"
70+
echo "changes=false" >> $GITHUB_OUTPUT
71+
else
72+
echo "Changes detected:"
73+
git diff --staged --name-only
74+
echo "changes=true" >> $GITHUB_OUTPUT
75+
fi
76+
77+
- name: Commit and push changes
78+
if: steps.check_changes.outputs.changes == 'true'
79+
run: |
80+
git config --local user.email "action@github.com"
81+
git config --local user.name "GitHub Action"
82+
git commit -m "chore: update benchmark results [skip ci]
83+
84+
Auto-generated by benchzribe tool
85+
- Updated README.md with latest benchmark results
86+
- Generated new benchmark graph
87+
88+
Triggered by: ${{ github.event_name }}
89+
Commit: ${{ github.sha }}"
90+
git push

README.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ A command-line tool for parsing, visualizing, and managing Go benchmark results.
66

77
- 📊 Parse Go benchmark results and generate formatted tables
88
- 📝 Automatically update README with benchmark results
9-
- 📈 Generate visualizations of benchmark data (coming soon)
9+
- 📈 Generate interactive visualizations of benchmark data
1010
- ⏱️ Track performance changes over time
1111
- 🔄 Easy integration with CI/CD pipelines
1212

@@ -28,21 +28,31 @@ go test -bench . -benchmem ./... > bench.out
2828
benchzribe run
2929
```
3030

31-
3. Generate performance graphs (coming soon):
31+
3. Generate interactive performance graphs:
3232
```bash
3333
benchzribe graph
3434
```
3535

3636
## 📊 Benchmark Results
3737

3838
<!-- BENCHSCRIBE:START -->
39+
### 📊 Benchmark Results
40+
41+
| Benchmark | ns/op | B/op | allocs/op |
42+
|-----------|-------|------|------------|
43+
| SimpleOperation-12 | 545 | 0 | 0 |
44+
| StringConcatenation-12 | 9766 | 21080 | 99 |
45+
| SliceOperations-12 | 619 | 0 | 0 |
46+
| TestHandler-12 | 3351 | 6139 | 19 |
47+
48+
_Last updated: Fri, 27 Jun 2025 02:02:30 BST_
3949

4050
<!-- BENCHSCRIBE:END -->
4151

4252
## 🛠️ Commands
4353

4454
- `benchzribe run` - Parse benchmark results and update README
45-
- `benchzribe graph` - Generate performance visualization (coming soon)
55+
- `benchzribe graph` - Generate interactive performance visualization
4656
- `benchzribe readme` - Manually update README section
4757

4858
## 🤝 Contributing

benchmark-graph.html

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
<!DOCTYPE html>
3+
<html>
4+
<head>
5+
<meta charset="utf-8">
6+
<title>Awesome go-echarts</title>
7+
<script src="https://go-echarts.github.io/go-echarts-assets/assets/echarts.min.js"></script>
8+
</head>
9+
10+
<body><div class="container">
11+
<div class="item" id="ghGUkJAHvaxJ" style="width:900px;height:500px;"></div>
12+
</div><script type="text/javascript">
13+
"use strict";
14+
let goecharts_ghGUkJAHvaxJ = echarts.init(document.getElementById('ghGUkJAHvaxJ'), "white", { renderer: "canvas" });
15+
let option_ghGUkJAHvaxJ = {"color":["#5470c6","#91cc75","#fac858","#ee6666","#73c0de","#3ba272","#fc8452","#9a60b4","#ea7ccc"],"legend":{"show":true},"series":[{"name":"ns/op","type":"line","data":[{"value":544.7},{"value":9766},{"value":619.1},{"value":3351}]},{"name":"B/op","type":"line","data":[{"value":0},{"value":21080},{"value":0},{"value":6139}]},{"name":"allocs/op","type":"line","data":[{"value":0},{"value":99},{"value":0},{"value":19}]}],"title":{"text":"Benchmark Results"},"toolbox":{},"tooltip":{"show":true,"trigger":"axis"},"xAxis":[{"data":["Benchmark 1","Benchmark 2","Benchmark 3","Benchmark 4"]}],"yAxis":[{}]}
16+
17+
goecharts_ghGUkJAHvaxJ.setOption(option_ghGUkJAHvaxJ);
18+
</script>
19+
<style>
20+
.container {margin-top:30px; display: flex;justify-content: center;align-items: center;}
21+
.item {margin: auto;}
22+
</style>
23+
</body>
24+
</html>

benchzribe

5.23 MB
Binary file not shown.

cmd/benchzribe/main.go

Lines changed: 4 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -71,50 +71,13 @@ func main() {
7171
}
7272

7373
func run() error {
74-
// Read benchmark results
75-
results, err := parser.Parse("bench.out")
76-
if err != nil {
77-
return fmt.Errorf("failed to parse benchmark results: %w", err)
78-
}
79-
80-
// Format results for README
81-
var readmeContent strings.Builder
82-
for _, r := range results {
83-
fmt.Fprintf(&readmeContent, "### %s\n", r.Name)
84-
fmt.Fprintf(&readmeContent, "- ns/op: %.2f\n", float64(r.NsPerOp))
85-
fmt.Fprintf(&readmeContent, "- B/op: %.2f\n", float64(r.BytesPerOp))
86-
fmt.Fprintf(&readmeContent, "- allocs/op: %.2f\n", float64(r.AllocsPerOp))
87-
}
88-
89-
// Update README
90-
if err := readme.Update("README.md", readmeContent.String()); err != nil {
91-
return fmt.Errorf("failed to update README: %w", err)
92-
}
93-
94-
return nil
74+
cfg := config.DefaultConfig()
75+
return handleRun(cfg)
9576
}
9677

9778
func generateGraph() error {
98-
// Read benchmark results
99-
results, err := parser.Parse("bench.out")
100-
if err != nil {
101-
return fmt.Errorf("failed to parse benchmark results: %w", err)
102-
}
103-
104-
// Convert results to graph data format
105-
data := make(map[string][]float64)
106-
for _, r := range results {
107-
data["ns/op"] = append(data["ns/op"], float64(r.NsPerOp))
108-
data["B/op"] = append(data["B/op"], float64(r.BytesPerOp))
109-
data["allocs/op"] = append(data["allocs/op"], float64(r.AllocsPerOp))
110-
}
111-
112-
// Generate graph
113-
if err := graph.GenerateGraph(data); err != nil {
114-
return fmt.Errorf("failed to generate graph: %w", err)
115-
}
116-
117-
return nil
79+
cfg := config.DefaultConfig()
80+
return handleGraph(cfg)
11881
}
11982

12083
func handleRun(cfg config.Config) error {

internal/graph/graph.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package graph
22

33
import (
4+
"fmt"
45
"os"
56

67
"github.com/go-echarts/go-echarts/v2/charts"
@@ -31,10 +32,15 @@ func GenerateGraph(data map[string][]float64) error {
3132
}),
3233
)
3334

34-
// Add X axis
35+
// Add X axis - use the first data series to determine length
3536
var xAxis []string
36-
for i := 0; i < len(data["ops"]); i++ {
37-
xAxis = append(xAxis, "Run "+string(rune('A'+i)))
37+
var dataLen int
38+
for _, values := range data {
39+
dataLen = len(values)
40+
break
41+
}
42+
for i := 0; i < dataLen; i++ {
43+
xAxis = append(xAxis, fmt.Sprintf("Benchmark %d", i+1))
3844
}
3945
line.SetXAxis(xAxis)
4046

test-ci-flow.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash
2+
3+
echo "🔧 Testing CI Flow for BenchZribe"
4+
echo "=================================="
5+
6+
echo "1. Building benchzribe..."
7+
go build -v -o benchzribe ./cmd/benchzribe
8+
9+
echo "2. Running benchmarks..."
10+
cd mockapi
11+
go test ./internal/benchmarks -bench=. -benchmem > ../bench.out
12+
cd ..
13+
14+
echo "3. Generated benchmark results:"
15+
cat bench.out
16+
17+
echo "4. Updating README with benchzribe..."
18+
./benchzribe run
19+
20+
echo "5. Generating graph..."
21+
./benchzribe graph
22+
23+
echo "6. Checking git status..."
24+
git status
25+
26+
echo "7. Files generated:"
27+
ls -la *.html *.out 2>/dev/null || echo "No graph/bench files found"
28+
29+
echo ""
30+
echo "✅ CI Flow test completed!"
31+
echo "The README should now contain updated benchmark results."
32+
echo "The benchmark-graph.html should contain an interactive chart."

0 commit comments

Comments
 (0)