Skip to content

Commit

Permalink
Add benchmark test
Browse files Browse the repository at this point in the history
  • Loading branch information
otiai10 committed Sep 7, 2023
1 parent 3eebd94 commit 0b8d7bd
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
19 changes: 18 additions & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ jobs:
os: [ubuntu-latest, macos-latest, windows-latest]
go: ['1.18', '1.19', '1.20']
steps:

- name: Set up Go
uses: actions/setup-go@v4
with:
Expand All @@ -34,3 +33,21 @@ jobs:

- name: Test
run: go test -v --tags=go${{ matrix.go }}
benchmark:
name: Benchmark
runs-on: ubuntu-latest
strategy:
matrix:
go: ['1.21']
steps:
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go }}
id: go
- name: Check out code into the Go module directory
uses: actions/checkout@v3
- name: Get dependencies
run: go get -v -t -d ./...
- name: Benchmark
run: go test -bench . -benchmem -benchtime 8s
38 changes: 38 additions & 0 deletions benchmark_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package copy

import (
"fmt"
"testing"
)

func BenchmarkOptions_NumberOfWorkers_0(b *testing.B) {
var num int64 = 0 // 0 or 1 = single-threaded
opt := Options{NumberOfWorkers: num}
for i := 0; i < b.N; i++ {
Copy("test/data/case19", fmt.Sprintf("test/data.copy/case19-%d-%d", num, i), opt)
}
}

func BenchmarkOptions_NumberOfWorkers_2(b *testing.B) {
var num int64 = 2
opt := Options{NumberOfWorkers: num}
for i := 0; i < b.N; i++ {
Copy("test/data/case19", fmt.Sprintf("test/data.copy/case19-%d-%d", num, i), opt)
}
}

func BenchmarkOptions_NumberOfWorkers_4(b *testing.B) {
var num int64 = 4
opt := Options{NumberOfWorkers: num}
for i := 0; i < b.N; i++ {
Copy("test/data/case19", fmt.Sprintf("test/data.copy/case19-%d-%d", num, i), opt)
}
}

func BenchmarkOptions_NumberOfWorkers_8(b *testing.B) {
var num int64 = 8
opt := Options{NumberOfWorkers: num}
for i := 0; i < b.N; i++ {
Copy("test/data/case19", fmt.Sprintf("test/data.copy/case19-%d-%d", num, i), opt)
}
}

0 comments on commit 0b8d7bd

Please sign in to comment.