]> Cypherpunks repositories - gostls13.git/commitdiff
fmt,math/big,net/url: fixes to old Benchmarks
authorEgon Elbre <egonelbre@gmail.com>
Mon, 22 May 2023 19:40:47 +0000 (22:40 +0300)
committerGopher Robot <gobot@golang.org>
Tue, 23 May 2023 20:25:13 +0000 (20:25 +0000)
b.ResetTimer used to also stop the timer, however it does not anymore.
These benchmarks hadn't been fixed and as a result ended up measuring
some additional things.

Also, make some for loops more conventional.

Change-Id: I76ca68456d85eec51722a80587e5b2c9f5d836a1
Reviewed-on: https://go-review.googlesource.com/c/go/+/496996
Run-TryBot: Damien Neil <dneil@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Auto-Submit: Damien Neil <dneil@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>

src/fmt/scan_test.go
src/math/big/int_test.go
src/net/url/url_test.go

index e8c5769924d682784011ca5fba8d980baea2fb4d..a4f80c23c2410063f25c212e6227f01c9a9553f1 100644 (file)
@@ -1096,10 +1096,10 @@ func testScanInts(t *testing.T, scan func(*RecursiveInt, *bytes.Buffer) error) {
 }
 
 func BenchmarkScanInts(b *testing.B) {
-       b.ResetTimer()
+       b.StopTimer()
        ints := makeInts(intCount)
        var r RecursiveInt
-       for i := b.N - 1; i >= 0; i-- {
+       for i := 0; i < b.N; i++ {
                buf := bytes.NewBuffer(ints)
                b.StartTimer()
                scanInts(&r, buf)
@@ -1108,10 +1108,10 @@ func BenchmarkScanInts(b *testing.B) {
 }
 
 func BenchmarkScanRecursiveInt(b *testing.B) {
-       b.ResetTimer()
+       b.StopTimer()
        ints := makeInts(intCount)
        var r RecursiveInt
-       for i := b.N - 1; i >= 0; i-- {
+       for i := 0; i < b.N; i++ {
                buf := bytes.NewBuffer(ints)
                b.StartTimer()
                Fscan(buf, &r)
@@ -1120,10 +1120,10 @@ func BenchmarkScanRecursiveInt(b *testing.B) {
 }
 
 func BenchmarkScanRecursiveIntReaderWrapper(b *testing.B) {
-       b.ResetTimer()
+       b.StopTimer()
        ints := makeInts(intCount)
        var r RecursiveInt
-       for i := b.N - 1; i >= 0; i-- {
+       for i := 0; i < b.N; i++ {
                buf := struct{ io.Reader }{strings.NewReader(string(ints))}
                b.StartTimer()
                Fscan(buf, &r)
index 2800d8f247bede52a50443b888d57d4db0af2a94..dfbc17242d583774659e433c4d90cf9dea218f40 100644 (file)
@@ -254,7 +254,7 @@ func TestBinomial(t *testing.T) {
 
 func BenchmarkBinomial(b *testing.B) {
        var z Int
-       for i := b.N - 1; i >= 0; i-- {
+       for i := 0; i < b.N; i++ {
                z.Binomial(1000, 990)
        }
 }
@@ -1425,7 +1425,6 @@ func BenchmarkBitset(b *testing.B) {
        z := new(Int)
        z.SetBit(z, 512, 1)
        b.ResetTimer()
-       b.StartTimer()
        for i := b.N - 1; i >= 0; i-- {
                z.SetBit(z, i&512, 1)
        }
@@ -1435,7 +1434,6 @@ func BenchmarkBitsetNeg(b *testing.B) {
        z := NewInt(-1)
        z.SetBit(z, 512, 0)
        b.ResetTimer()
-       b.StartTimer()
        for i := b.N - 1; i >= 0; i-- {
                z.SetBit(z, i&512, 0)
        }
@@ -1445,7 +1443,6 @@ func BenchmarkBitsetOrig(b *testing.B) {
        z := new(Int)
        altSetBit(z, z, 512, 1)
        b.ResetTimer()
-       b.StartTimer()
        for i := b.N - 1; i >= 0; i-- {
                altSetBit(z, z, i&512, 1)
        }
@@ -1455,7 +1452,6 @@ func BenchmarkBitsetNegOrig(b *testing.B) {
        z := NewInt(-1)
        altSetBit(z, z, 512, 0)
        b.ResetTimer()
-       b.StartTimer()
        for i := b.N - 1; i >= 0; i-- {
                altSetBit(z, z, i&512, 0)
        }
index 577cf631c835e1986ff65107dc1cd9fc32651cd3..23c5c581c5a7d0e440e959bf529c4fce52000a93 100644 (file)
@@ -1116,7 +1116,6 @@ func TestResolvePath(t *testing.T) {
 }
 
 func BenchmarkResolvePath(b *testing.B) {
-       b.ResetTimer()
        b.ReportAllocs()
        for i := 0; i < b.N; i++ {
                resolvePath("a/b/c", ".././d")