summaryrefslogtreecommitdiff
path: root/test/bench/regex-dna.go
diff options
context:
space:
mode:
authorRob Pike <r@golang.org>2009-08-05 17:25:38 -0700
committerRob Pike <r@golang.org>2009-08-05 17:25:38 -0700
commit2e6b62d4d2230d39a313483849597fd747a3e98c (patch)
treea4f81ca947c34f18bb24db161bd966c878b31f76 /test/bench/regex-dna.go
parent8b5f87a023f0ac728c619e34d9295a1e664f197c (diff)
downloadgolang-2e6b62d4d2230d39a313483849597fd747a3e98c.tar.gz
spectral-norm
make regexp-dna use bytes not strings (no significant timing change) R=rsc DELTA=149 (138 added, 1 deleted, 10 changed) OCL=32804 CL=32807
Diffstat (limited to 'test/bench/regex-dna.go')
-rw-r--r--test/bench/regex-dna.go20
1 files changed, 10 insertions, 10 deletions
diff --git a/test/bench/regex-dna.go b/test/bench/regex-dna.go
index c0ade94e7..ee4ddfd50 100644
--- a/test/bench/regex-dna.go
+++ b/test/bench/regex-dna.go
@@ -40,6 +40,7 @@ import (
"io";
"os";
"regexp";
+ "strings";
)
func compile(s string) *regexp.Regexp {
@@ -81,17 +82,17 @@ var substs = [] Subst {
Subst {"Y", "(c|t)"},
}
-func countMatches(pat, str string) int {
+func countMatches(pat string, bytes []byte) int {
re := compile(pat);
n := 0;
pos := 0;
for {
- e := re.Execute(str);
+ e := re.Execute(bytes);
if len(e) == 0 {
break;
}
n++;
- str = str[e[1]:len(str)];
+ bytes = bytes[e[1]:len(bytes)];
}
return n;
}
@@ -102,16 +103,15 @@ func main() {
fmt.Fprintf(os.Stderr, "can't read input: %s\n", err);
os.Exit(2);
}
- str := string(bytes);
- ilen := len(str);
+ ilen := len(bytes);
// Delete the comment lines and newlines
- str = compile("(>[^\n]+)?\n").ReplaceAll(str, "");
- clen := len(str);
+ bytes = compile("(>[^\n]+)?\n").ReplaceAll(bytes, []byte{});
+ clen := len(bytes);
for i, s := range variants {
- fmt.Printf("%s %d\n", s, countMatches(s, str));
+ fmt.Printf("%s %d\n", s, countMatches(s, bytes));
}
for i, sub := range substs {
- str = compile(sub.pat).ReplaceAll(str, sub.repl);
+ bytes = compile(sub.pat).ReplaceAll(bytes, strings.Bytes(sub.repl));
}
- fmt.Printf("\n%d\n%d\n%d\n", ilen, clen, len(str));
+ fmt.Printf("\n%d\n%d\n%d\n", ilen, clen, len(bytes));
}