performance measurements

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,0001.231.247,004733  0% 2% 2% 99%
500,00012.2512.2659,652733  0% 1% 1% 100%
5,000,000120.81120.87548,932733  1% 0% 1% 100%

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.

 notes

go version go1.3 linux/amd64

See "Regular Expression Matching Can Be Simple And Fast (but is slow in Java, Perl, PHP, Python, Ruby, ...)" Russ Cox, January 2007

 regex-dna Go program source code

/* 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)
}

 make, command-line, and program output logs

Thu, 19 Jun 2014 08:41:23 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

Revised BSD license

  Home   Conclusions   License   Play