Skip to content

Commit

Permalink
Add benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
lucashorward committed Feb 14, 2024
1 parent 38ee878 commit 62da8f3
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 12 deletions.
26 changes: 14 additions & 12 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,26 @@ name: Go

on:
push:
branches: [ "main" ]
branches: ["main"]
pull_request:
branches: [ "main" ]
branches: ["main"]

jobs:

build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: "1.22"

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.22'
- name: Build
run: go build -v ./...

- name: Build
run: go build -v ./...
- name: Test
run: go test -v ./...

- name: Test
run: go test -v ./...
- name: Test
run: go test -bench .
25 changes: 25 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,28 @@ func TestGuessOutOfBounds(t *testing.T) {
t.Fatalf("Guess Error must be about the guess being Out Of Bounds, but was %q", err)
}
}

func BenchmarkCreate(b *testing.B) {
for i := 0; i < b.N; i++ {
input := newGame{
Min: i,
Max: i + 100,
}
CreateGame(&input)
}
}

func BenchmarkCreateAndGuess(b *testing.B) {
for i := 0; i < b.N; i++ {
input := newGame{
Min: i,
Max: i + 50,
}
response, _ := CreateGame(&input)
guess := guess{
GameId: response.Id,
Guess: i + 25,
}
Guess(&guess)
}
}

0 comments on commit 62da8f3

Please sign in to comment.