Skip to content
This repository was archived by the owner on Mar 8, 2020. It is now read-only.

Commit 9085dab

Browse files
committed
test: drop experimental benchmark
Signed-off-by: Alexander Bezzubov <[email protected]>
1 parent 3f88050 commit 9085dab

File tree

2 files changed

+3
-66
lines changed

2 files changed

+3
-66
lines changed

driver/normalizer/strconv.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,11 @@ func contains(s string, c byte) bool {
6060
return strings.IndexByte(s, c) >= 0
6161
}
6262

63-
// replaceEscapedMaybe returns a copy of s in which occurrences of old followed by a
63+
// replaceEscapedMaybe returns a copy of s in which occurrences of old followed by a
6464
// non-digit are replaced by repl.
6565
// Is not part of the stdlib, handles the special case of JS escape sequence.
66+
// Regexp replacement and manual expansion performance was tested against the
67+
// current implementation and found this was fastest.
6668
func replaceEscapedMaybe(s, old, repl string) string {
6769
var out strings.Builder
6870
for s != "" {

driver/normalizer/strconv_test.go

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
package normalizer
22

33
import (
4-
"regexp"
54
"testing"
6-
"unicode/utf8"
75

86
"github.com/stretchr/testify/assert"
97
"github.com/stretchr/testify/require"
@@ -70,69 +68,6 @@ func printDebug(t *testing.T, quoted, actual string) {
7068
}
7169
}
7270

73-
func BenchmarkReplacingNullEscape_Iterative(b *testing.B) {
74-
b.ReportAllocs()
75-
for _, test := range testCasesUnquote {
76-
for n := 0; n < b.N; n++ {
77-
replaceEscapedMaybeIter(test.quoted, '0', '\x00')
78-
}
79-
}
80-
}
81-
82-
// replaceEscapedMaybeIter is alternative implementation of replaceEscapedMaybe
83-
// It is only used in benchmark tests for performance comparison.
84-
func replaceEscapedMaybeIter(s string, old, new rune) string {
85-
var runeTmp [utf8.UTFMax]byte
86-
n := utf8.EncodeRune(runeTmp[:], new)
87-
88-
lastCp := 0
89-
var buf []byte
90-
for i, w := 0, 0; i < len(s); i += w {
91-
r1, w1 := utf8.DecodeRuneInString(s[i:])
92-
w = w1
93-
if r1 == '\\' { // find sequence \\old[^0-9]
94-
r2, w2 := utf8.DecodeRuneInString(s[i+w1:])
95-
if r2 == old {
96-
r3, _ := utf8.DecodeRuneInString(s[i+w1+w2:])
97-
if 0 > r3 || r3 > 9 { // not a number after "\\old"
98-
w += w2
99-
if len(buf) == 0 {
100-
buf = make([]byte, 0, 3*len(s)/2)
101-
}
102-
buf = append(buf, []byte(s[lastCp:i])...)
103-
buf = append(buf, runeTmp[:n]...)
104-
lastCp = i + w
105-
}
106-
}
107-
}
108-
}
109-
if lastCp == 0 {
110-
return s
111-
}
112-
113-
if 0 < lastCp && lastCp < len(s) {
114-
return string(append(buf, []byte(s[lastCp:len(s)])...))
115-
}
116-
return string(buf)
117-
}
118-
119-
func BenchmarkReplacingNullEscape_Regexp(b *testing.B) {
120-
b.ReportAllocs()
121-
for _, test := range testCasesUnquote {
122-
for n := 0; n < b.N; n++ {
123-
replaceEscapedMaybeRegexp(test.quoted)
124-
}
125-
}
126-
}
127-
128-
var re = regexp.MustCompile(`\\0([^0-9]|$)`)
129-
130-
// replaceEscapedMaybeRegexp is alternative implementation of replaceEscapedMaybe
131-
// It is only used in benchmark tests for performance comparison.
132-
func replaceEscapedMaybeRegexp(s string) string {
133-
return re.ReplaceAllString(s, "\x00$1")
134-
}
135-
13671
func BenchmarkReplacingNullEscape_Simple(b *testing.B) {
13772
b.ReportAllocs()
13873
for _, test := range testCasesUnquote {

0 commit comments

Comments
 (0)