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

create time with precision function for benchmark #732

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions ginkgo_dsl.go
Expand Up @@ -190,6 +190,7 @@ func CurrentGinkgoTestDescription() GinkgoTestDescription {
//See http://onsi.github.io/ginkgo/#benchmark_tests for more details
type Benchmarker interface {
Time(name string, body func(), info ...interface{}) (elapsedTime time.Duration)
TimeWithPrecision(name string, body func(), units string, precision int, info ...interface{}) (elapsedTime time.Duration)
RecordValue(name string, value float64, info ...interface{})
RecordValueWithPrecision(name string, value float64, units string, precision int, info ...interface{})
}
Expand Down
13 changes: 13 additions & 0 deletions internal/leafnodes/benchmarker.go
Expand Up @@ -34,6 +34,19 @@ func (b *benchmarker) Time(name string, body func(), info ...interface{}) (elaps
return
}

func (b *benchmarker) TimeWithPrecision(name string, body func(), units string, precision int, info ...interface{}) (elapsedTime time.Duration) {
t := time.Now()
body()
elapsedTime = time.Since(t)

b.mu.Lock()
defer b.mu.Unlock()
measurement := b.getMeasurement(name, "Fastest Time", "Slowest Time", "Average Time", units, precision, info...)
measurement.Results = append(measurement.Results, elapsedTime.Seconds())

return
}

func (b *benchmarker) RecordValue(name string, value float64, info ...interface{}) {
b.mu.Lock()
measurement := b.getMeasurement(name, "Smallest", " Largest", " Average", "", 3, info...)
Expand Down