1
0
mirror of https://github.com/golang/go synced 2024-11-19 16:34:49 -07:00

testing: make ResetTimer not start/stop the timer

R=r
CC=golang-dev
https://golang.org/cl/4626085
This commit is contained in:
Russ Cox 2011-06-29 10:26:16 -04:00
parent 25733a94fd
commit b2127a6c99

View File

@ -35,7 +35,11 @@ type B struct {
// StartTimer starts timing a test. This function is called automatically // StartTimer starts timing a test. This function is called automatically
// before a benchmark starts, but it can also used to resume timing after // before a benchmark starts, but it can also used to resume timing after
// a call to StopTimer. // a call to StopTimer.
func (b *B) StartTimer() { b.start = time.Nanoseconds() } func (b *B) StartTimer() {
if b.start == 0 {
b.start = time.Nanoseconds()
}
}
// StopTimer stops timing a test. This can be used to pause the timer // StopTimer stops timing a test. This can be used to pause the timer
// while performing complex initialization that you don't // while performing complex initialization that you don't
@ -47,9 +51,12 @@ func (b *B) StopTimer() {
b.start = 0 b.start = 0
} }
// ResetTimer stops the timer and sets the elapsed benchmark time to zero. // ResetTimer sets the elapsed benchmark time to zero.
// It does not affect whether the timer is running.
func (b *B) ResetTimer() { func (b *B) ResetTimer() {
b.start = 0 if b.start > 0 {
b.start = time.Nanoseconds()
}
b.ns = 0 b.ns = 0
} }