]> Cypherpunks repositories - gostls13.git/commitdiff
testing: make ResetTimer not start/stop the timer
authorRuss Cox <rsc@golang.org>
Wed, 29 Jun 2011 14:26:16 +0000 (10:26 -0400)
committerRuss Cox <rsc@golang.org>
Wed, 29 Jun 2011 14:26:16 +0000 (10:26 -0400)
R=r
CC=golang-dev
https://golang.org/cl/4626085

src/pkg/testing/benchmark.go

index 4d5ff6c77688a91475b7456c316fe46b89adaf81..3b416acfaf8653cc9a830f65565a7cc3371b0f8b 100644 (file)
@@ -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
 }