Skip to content

Commit

Permalink
test(benchmark): add benchmarks for NewWorklog
Browse files Browse the repository at this point in the history
  • Loading branch information
gabor-boros committed Oct 8, 2021
1 parent b73017b commit 87f6767
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions internal/pkg/worklog/worklog_test.go
Expand Up @@ -2,11 +2,53 @@ package worklog_test

import (
"testing"
"time"

"github.com/gabor-boros/minutes/internal/pkg/worklog"
"github.com/stretchr/testify/assert"
)

var worklogBenchResult worklog.Worklog

func benchmarkNewWorklog(b *testing.B, entryCount int) {
b.StopTimer()

var entries []worklog.Entry

for i := 0; i != entryCount; i++ {
entry := getTestEntry()
entry.Start.Add(time.Hour * time.Duration(i))
entries = append(entries, entry)
}

b.StartTimer()

var result worklog.Worklog
for n := 0; n != b.N; n++ {
result = worklog.NewWorklog(entries)
}

// always store the result to a package level variable
// so the compiler cannot eliminate the Benchmark itself.
worklogBenchResult = result
}

func BenchmarkNewWorklog_5(b *testing.B) {
benchmarkNewWorklog(b, 5)
}

func BenchmarkNewWorklog_10(b *testing.B) {
benchmarkNewWorklog(b, 10)
}

func BenchmarkNewWorklog_50(b *testing.B) {
benchmarkNewWorklog(b, 50)
}

func BenchmarkNewWorklog_100(b *testing.B) {
benchmarkNewWorklog(b, 100)
}

func TestWorklogCompleteEntries(t *testing.T) {
completeEntry := getTestEntry()

Expand Down

0 comments on commit 87f6767

Please sign in to comment.