diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 8413309..a6b05d2 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -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: @@ -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 \ No newline at end of file diff --git a/benchmark_test.go b/benchmark_test.go new file mode 100644 index 0000000..0817440 --- /dev/null +++ b/benchmark_test.go @@ -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) + } +}