/mobile Handheld Friendly website
x64 Ubuntu : Intel® Q6600® quad-core |
Each table row shows performance measurements for this Go program with a particular command-line input value N.
| N | CPU secs | Elapsed secs | Memory KB | Code B | ≈ CPU Load |
|---|---|---|---|---|---|
| 50,000 | 1.61 | 0.64 | 4,332 | 733 | 66% 57% 77% 56% |
| 500,000 | 16.16 | 6.28 | 61,660 | 733 | 56% 57% 77% 69% |
| 5,000,000 | 157.24 | 60.04 | 574,724 | 733 | 71% 63% 65% 63% |
Read the ↓ make, command line, and program output logs to see how this program was run.
Read regex-dna benchmark to see what this program should do.
go version go1.1.1 linux/amd64
See "Regular Expression Matching Can Be Simple And Fast (but is slow in Java, Perl, PHP, Python, Ruby, ...)" Russ Cox, January 2007
/* The Computer Language Benchmarks Game * http://benchmarksgame.alioth.debian.org/ * * contributed by The Go Authors. */ package main import ( "fmt" "io/ioutil" "os" "runtime" "regexp" ) var variants = []string{ "agggtaaa|tttaccct", "[cgt]gggtaaa|tttaccc[acg]", "a[act]ggtaaa|tttacc[agt]t", "ag[act]gtaaa|tttac[agt]ct", "agg[act]taaa|ttta[agt]cct", "aggg[acg]aaa|ttt[cgt]ccct", "agggt[cgt]aa|tt[acg]accct", "agggta[cgt]a|t[acg]taccct", "agggtaa[cgt]|[acg]ttaccct", } type Subst struct { pat, repl string } var substs = []Subst{ Subst{"B", "(c|g|t)"}, Subst{"D", "(a|g|t)"}, Subst{"H", "(a|c|t)"}, Subst{"K", "(g|t)"}, Subst{"M", "(a|c)"}, Subst{"N", "(a|c|g|t)"}, Subst{"R", "(a|g)"}, Subst{"S", "(c|g)"}, Subst{"V", "(a|c|g)"}, Subst{"W", "(a|t)"}, Subst{"Y", "(c|t)"}, } func countMatches(pat string, bytes []byte) int { re := regexp.MustCompile(pat) n := 0 for { e := re.FindIndex(bytes) if e == nil { break } n++ bytes = bytes[e[1]:] } return n } func main() { runtime.GOMAXPROCS(4) bytes, err := ioutil.ReadFile("/dev/stdin") if err != nil { fmt.Fprintf(os.Stderr, "can't read input: %s\n", err) os.Exit(2) } ilen := len(bytes) // Delete the comment lines and newlines bytes = regexp.MustCompile("(>[^\n]+)?\n").ReplaceAll(bytes, []byte{}) clen := len(bytes) mresults := make([]chan int, len(variants)) for i, s := range variants { ch := make(chan int) mresults[i] = ch go func(ss string) { ch <- countMatches(ss, bytes) }(s) } lenresult := make(chan int) bb := bytes go func() { for _, sub := range substs { bb = regexp.MustCompile(sub.pat).ReplaceAll(bb, []byte(sub.repl)) } lenresult <- len(bb) }() for i, s := range variants { fmt.Printf("%s %d\n", s, <-mresults[i]) } fmt.Printf("\n%d\n%d\n%d\n", ilen, clen, <-lenresult) }
Thu, 13 Jun 2013 18:17:11 GMT MAKE: /usr/local/src/go/bin/go build -o regexdna.go_run 0.37s to complete and log all make actions COMMAND LINE: ./regexdna.go_run 0 < regexdna-input5000000.txt PROGRAM OUTPUT: agggtaaa|tttaccct 356 [cgt]gggtaaa|tttaccc[acg] 1250 a[act]ggtaaa|tttacc[agt]t 4252 ag[act]gtaaa|tttac[agt]ct 2894 agg[act]taaa|ttta[agt]cct 5435 aggg[acg]aaa|ttt[cgt]ccct 1537 agggt[cgt]aa|tt[acg]accct 1431 agggta[cgt]a|t[acg]taccct 1608 agggtaa[cgt]|[acg]ttaccct 2178 50833411 50000000 66800214