regexp: avoid allocation of input interface
Matters most for small inputs, because there is no real work
to amortize the allocation effort against.
benchmark old ns/op new ns/op delta
BenchmarkLiteral 613 473 -22.84%
BenchmarkNotLiteral 4981 4931 -1.00%
BenchmarkMatchClass 7289 7122 -2.29%
BenchmarkMatchClass_InRange 6618 6663 +0.68%
BenchmarkReplaceAll 7843 7233 -7.78%
BenchmarkAnchoredLiteralShortNonMatch 329 228 -30.70%
BenchmarkAnchoredLiteralLongNonMatch 322 228 -29.19%
BenchmarkAnchoredShortMatch 838 715 -14.68%
BenchmarkAnchoredLongMatch 824 715 -13.23%
benchmark old MB/s new MB/s speedup
BenchmarkMatchEasy0_32 119.73 196.61 1.64x
BenchmarkMatchEasy0_1K 540.58 538.33 1.00x
BenchmarkMatchEasy0_32K 732.57 714.00 0.97x
BenchmarkMatchEasy0_1M 726.44 708.36 0.98x
BenchmarkMatchEasy0_32M 707.77 691.45 0.98x
BenchmarkMatchEasy1_32 102.12 136.11 1.33x
BenchmarkMatchEasy1_1K 298.31 307.04 1.03x
BenchmarkMatchEasy1_32K 273.56 274.43 1.00x
BenchmarkMatchEasy1_1M 268.42 269.23 1.00x
BenchmarkMatchEasy1_32M 266.15 267.34 1.00x
BenchmarkMatchMedium_32 2.53 3.38 1.34x
BenchmarkMatchMedium_1K 9.37 9.57 1.02x
BenchmarkMatchMedium_32K 9.29 9.67 1.04x
BenchmarkMatchMedium_1M 9.42 9.66 1.03x
BenchmarkMatchMedium_32M 9.41 9.62 1.02x
BenchmarkMatchHard_32 6.66 6.75 1.01x
BenchmarkMatchHard_1K 6.81 6.85 1.01x
BenchmarkMatchHard_32K 6.79 6.85 1.01x
BenchmarkMatchHard_1M 6.82 6.83 1.00x
BenchmarkMatchHard_32M 6.80 6.80 1.00x
R=golang-dev, r
CC=golang-dev
https://golang.org/cl/5453076
diff --git a/src/pkg/regexp/exec_test.go b/src/pkg/regexp/exec_test.go
index d981f54..312bf02 100644
--- a/src/pkg/regexp/exec_test.go
+++ b/src/pkg/regexp/exec_test.go
@@ -10,7 +10,6 @@
"fmt"
"io"
"math/rand"
- old "old/regexp"
"os"
"path/filepath"
"regexp/syntax"
@@ -679,18 +678,6 @@
}
}
-func benchold(b *testing.B, re string, n int) {
- r := old.MustCompile(re)
- t := makeText(n)
- b.ResetTimer()
- b.SetBytes(int64(n))
- for i := 0; i < b.N; i++ {
- if r.Match(t) {
- panic("match!")
- }
- }
-}
-
const (
easy0 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ$"
easy1 = "A[AB]B[BC]C[CD]D[DE]E[EF]F[FG]G[GH]H[HI]I[IJ]J$"
@@ -700,35 +687,23 @@
"(N)(O)(P)(Q)(R)(S)(T)(U)(V)(W)(X)(Y)(Z)$"
)
-func BenchmarkMatchEasy0_1K(b *testing.B) { benchmark(b, easy0, 1<<10) }
-func BenchmarkMatchEasy0_1K_Old(b *testing.B) { benchold(b, easy0, 1<<10) }
-func BenchmarkMatchEasy0_1M(b *testing.B) { benchmark(b, easy0, 1<<20) }
-func BenchmarkMatchEasy0_1M_Old(b *testing.B) { benchold(b, easy0, 1<<20) }
-func BenchmarkMatchEasy0_32K(b *testing.B) { benchmark(b, easy0, 32<<10) }
-func BenchmarkMatchEasy0_32K_Old(b *testing.B) { benchold(b, easy0, 32<<10) }
-func BenchmarkMatchEasy0_32M(b *testing.B) { benchmark(b, easy0, 32<<20) }
-func BenchmarkMatchEasy0_32M_Old(b *testing.B) { benchold(b, easy0, 32<<20) }
-func BenchmarkMatchEasy1_1K(b *testing.B) { benchmark(b, easy1, 1<<10) }
-func BenchmarkMatchEasy1_1K_Old(b *testing.B) { benchold(b, easy1, 1<<10) }
-func BenchmarkMatchEasy1_1M(b *testing.B) { benchmark(b, easy1, 1<<20) }
-func BenchmarkMatchEasy1_1M_Old(b *testing.B) { benchold(b, easy1, 1<<20) }
-func BenchmarkMatchEasy1_32K(b *testing.B) { benchmark(b, easy1, 32<<10) }
-func BenchmarkMatchEasy1_32K_Old(b *testing.B) { benchold(b, easy1, 32<<10) }
-func BenchmarkMatchEasy1_32M(b *testing.B) { benchmark(b, easy1, 32<<20) }
-func BenchmarkMatchEasy1_32M_Old(b *testing.B) { benchold(b, easy1, 32<<20) }
-func BenchmarkMatchMedium_1K(b *testing.B) { benchmark(b, medium, 1<<10) }
-func BenchmarkMatchMedium_1K_Old(b *testing.B) { benchold(b, medium, 1<<10) }
-func BenchmarkMatchMedium_1M(b *testing.B) { benchmark(b, medium, 1<<20) }
-func BenchmarkMatchMedium_1M_Old(b *testing.B) { benchold(b, medium, 1<<20) }
-func BenchmarkMatchMedium_32K(b *testing.B) { benchmark(b, medium, 32<<10) }
-func BenchmarkMatchMedium_32K_Old(b *testing.B) { benchold(b, medium, 32<<10) }
-func BenchmarkMatchMedium_32M(b *testing.B) { benchmark(b, medium, 32<<20) }
-func BenchmarkMatchMedium_32M_Old(b *testing.B) { benchold(b, medium, 32<<20) }
-func BenchmarkMatchHard_1K(b *testing.B) { benchmark(b, hard, 1<<10) }
-func BenchmarkMatchHard_1K_Old(b *testing.B) { benchold(b, hard, 1<<10) }
-func BenchmarkMatchHard_1M(b *testing.B) { benchmark(b, hard, 1<<20) }
-func BenchmarkMatchHard_1M_Old(b *testing.B) { benchold(b, hard, 1<<20) }
-func BenchmarkMatchHard_32K(b *testing.B) { benchmark(b, hard, 32<<10) }
-func BenchmarkMatchHard_32K_Old(b *testing.B) { benchold(b, hard, 32<<10) }
-func BenchmarkMatchHard_32M(b *testing.B) { benchmark(b, hard, 32<<20) }
-func BenchmarkMatchHard_32M_Old(b *testing.B) { benchold(b, hard, 32<<20) }
+func BenchmarkMatchEasy0_32(b *testing.B) { benchmark(b, easy0, 32<<0) }
+func BenchmarkMatchEasy0_1K(b *testing.B) { benchmark(b, easy0, 1<<10) }
+func BenchmarkMatchEasy0_32K(b *testing.B) { benchmark(b, easy0, 32<<10) }
+func BenchmarkMatchEasy0_1M(b *testing.B) { benchmark(b, easy0, 1<<20) }
+func BenchmarkMatchEasy0_32M(b *testing.B) { benchmark(b, easy0, 32<<20) }
+func BenchmarkMatchEasy1_32(b *testing.B) { benchmark(b, easy1, 32<<0) }
+func BenchmarkMatchEasy1_1K(b *testing.B) { benchmark(b, easy1, 1<<10) }
+func BenchmarkMatchEasy1_32K(b *testing.B) { benchmark(b, easy1, 32<<10) }
+func BenchmarkMatchEasy1_1M(b *testing.B) { benchmark(b, easy1, 1<<20) }
+func BenchmarkMatchEasy1_32M(b *testing.B) { benchmark(b, easy1, 32<<20) }
+func BenchmarkMatchMedium_32(b *testing.B) { benchmark(b, medium, 1<<0) }
+func BenchmarkMatchMedium_1K(b *testing.B) { benchmark(b, medium, 1<<10) }
+func BenchmarkMatchMedium_32K(b *testing.B) { benchmark(b, medium, 32<<10) }
+func BenchmarkMatchMedium_1M(b *testing.B) { benchmark(b, medium, 1<<20) }
+func BenchmarkMatchMedium_32M(b *testing.B) { benchmark(b, medium, 32<<20) }
+func BenchmarkMatchHard_32(b *testing.B) { benchmark(b, hard, 32<<0) }
+func BenchmarkMatchHard_1K(b *testing.B) { benchmark(b, hard, 1<<10) }
+func BenchmarkMatchHard_32K(b *testing.B) { benchmark(b, hard, 32<<10) }
+func BenchmarkMatchHard_1M(b *testing.B) { benchmark(b, hard, 1<<20) }
+func BenchmarkMatchHard_32M(b *testing.B) { benchmark(b, hard, 32<<20) }