Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add github-action-benchmark #8

Merged
merged 4 commits into from
Nov 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading