From: Russ Cox Date: Wed, 29 Jun 2011 14:26:16 +0000 (-0400) Subject: testing: make ResetTimer not start/stop the timer X-Git-Tag: weekly.2011-07-07~75 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=b2127a6c9980d322ee67147c1c71f3d17e6cbd2f;p=gostls13.git testing: make ResetTimer not start/stop the timer R=r CC=golang-dev https://golang.org/cl/4626085 --- diff --git a/src/pkg/testing/benchmark.go b/src/pkg/testing/benchmark.go index 4d5ff6c776..3b416acfaf 100644 --- a/src/pkg/testing/benchmark.go +++ b/src/pkg/testing/benchmark.go @@ -35,7 +35,11 @@ type B struct { // StartTimer starts timing a test. This function is called automatically // before a benchmark starts, but it can also used to resume timing after // 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 // while performing complex initialization that you don't @@ -47,9 +51,12 @@ func (b *B) StopTimer() { 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() { - b.start = 0 + if b.start > 0 { + b.start = time.Nanoseconds() + } b.ns = 0 }