From 8764ebee95803d7eb9c1ef70b4ae54b10c0d0f29 Mon Sep 17 00:00:00 2001 From: Rob Pike Date: Wed, 5 Aug 2009 17:25:38 -0700 Subject: [PATCH] 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 --- test/bench/regex-dna.go | 20 ++++---- test/bench/spectral-norm.c | 82 +++++++++++++++++++++++++++++++ test/bench/spectral-norm.go | 95 ++++++++++++++++++++++++++++++++++++ test/bench/spectral-norm.txt | 1 + test/bench/timing.log | 8 +++ test/bench/timing.sh | 10 +++- 6 files changed, 205 insertions(+), 11 deletions(-) create mode 100644 test/bench/spectral-norm.c create mode 100644 test/bench/spectral-norm.go create mode 100644 test/bench/spectral-norm.txt diff --git a/test/bench/regex-dna.go b/test/bench/regex-dna.go index c0ade94e7a..ee4ddfd500 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)); } diff --git a/test/bench/spectral-norm.c b/test/bench/spectral-norm.c new file mode 100644 index 0000000000..832eb3d217 --- /dev/null +++ b/test/bench/spectral-norm.c @@ -0,0 +1,82 @@ +/* +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + * Neither the name of "The Computer Language Benchmarks Game" nor the + name of "The Computer Language Shootout Benchmarks" nor the names of + its contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. +*/ + +/* -*- mode: c -*- + * + * The Great Computer Language Shootout + * http://shootout.alioth.debian.org/ + * + * Contributed by Sebastien Loisel + */ + +#include +#include +#include + +double eval_A(int i, int j) { return 1.0/((i+j)*(i+j+1)/2+i+1); } + +void eval_A_times_u(int N, const double u[], double Au[]) +{ + int i,j; + for(i=0;i>1 instead of /2 : gc gives 24.33u 0.00s 24.33r] + diff --git a/test/bench/timing.sh b/test/bench/timing.sh index f481b0ac4e..87fd005236 100755 --- a/test/bench/timing.sh +++ b/test/bench/timing.sh @@ -76,9 +76,17 @@ regexdna() { rm x } +spectralnorm() { + echo 'spectral-norm 5500' + run 'gcc -O2 spectral-norm.c -lm' a.out 5500 + run 'gccgo -O2 spectral-norm.go' a.out -n 5500 + run 'gc spectral-norm' $O.out -n 5500 + run 'gc_B spectral-norm' $O.out -n 5500 +} + case $# in 0) - run="fasta revcom nbody binarytree fannkuch regexdna" + run="fasta revcom nbody binarytree fannkuch regexdna spectralnorm" ;; *) run=$* -- 2.48.1