Skip to content

Commit

Permalink
feat: add github-action-benchmark (#8)
Browse files Browse the repository at this point in the history
* feat: add github-action-benchmark

* update benchmark.yml

* update readme

* update benchmarks
  • Loading branch information
Skyenought authored Nov 19, 2023
1 parent 95179ca commit 457fbba
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 16 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
on:
push:
paths:
- '**'
- "!**.md"
pull_request:
paths:
- '**'
- "!**.md"
name: Benchmark
jobs:
compare:
runs-on: ubuntu-20.04
steps:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.version }}
- name: Fetch Repository
uses: actions/checkout@v3
- name: Run Benchmark
run: set -o pipefail; go test ./... -benchmem -run=^$ -bench . | tee output.txt
- name: Get Previous Benchmark Results
uses: actions/cache@v3
with:
path: ./cache
key: ${{ runner.os }}-benchmark
- name: Save Benchmark Results
uses: benchmark-action/github-action-benchmark@v1.16.2
with:
tool: 'go'
output-file-path: output.txt
github-token: ${{ secrets.GITHUB_TOKEN }}
benchmark-data-dir-path: 'benchmarks'
fail-on-alert: true
comment-on-alert: true
auto-push: ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch' }}
save-data-file: ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch' }}
10 changes: 0 additions & 10 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,6 @@ jobs:
with:
go-version: ${{ matrix.go }}

# block scenario, comment temporarily
# - uses: actions/cache@v3
# with:
# path: ~/go/pkg/mod
# key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
# restore-keys: |
# ${{ runner.os }}-go-

- name: Unit Test
run: go test -race -covermode=atomic -coverprofile=coverage.out ./...

- name: Benchmark
run: go test -bench=. -benchmem -run=none ./...
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,11 @@ curl -N --location 'http://localhost:8888/chat/sse?username=hertz'
#
#event:direct
#data:{"Type":"direct","From":"kitex","To":"hertz","Message":"hello hertz","Timestamp":"2023-04-10T23:48:56.212855+08:00"}
#

```
```

## Benchmark Results

All benchmarks are stored for each commit, they can be viewed here:

https://hertz-contrib.github.io/sse/benchmarks/
10 changes: 8 additions & 2 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,12 @@ curl -N --location 'http://localhost:8888/chat/sse?username=hertz'
#
#event:direct
#data:{"Type":"direct","From":"kitex","To":"hertz","Message":"hello hertz","Timestamp":"2023-04-10T23:48:56.212855+08:00"}
#

```
```


## Benchmark 结果

每次提交的所有的 Benchmark 结果都已存储,可在此处进行查看:

https://hertz-contrib.github.io/sse/benchmarks/
4 changes: 2 additions & 2 deletions encoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,10 @@ func BenchmarkNoRetrySSE(b *testing.B) {
}

func BenchmarkSimpleSSE(b *testing.B) {
b.ResetTimer()
b.ReportAllocs()
buf := new(bytes.Buffer)

b.ResetTimer()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
_ = Encode(buf, &Event{
Event: "new_message",
Expand Down

0 comments on commit 457fbba

Please sign in to comment.