1 ! Copyright (C) 2008 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors regexp prettyprint io io.encodings.ascii
4 io.files kernel sequences assocs namespaces ;
5 IN: benchmark.regex-dna
7 ! Based on http://shootout.alioth.debian.org/gp4/benchmark.php?test=regexdna&lang=ruby&id=1
9 : strip-line-breaks ( string -- string' )
10 R/ >.*\n|\n/ "" re-replace ;
12 : count-patterns ( string -- )
14 R/ agggtaaa|tttaccct/i
15 R/ [cgt]gggtaaa|tttaccc[acg]/i
16 R/ a[act]ggtaaa|tttacc[agt]t/i
17 R/ ag[act]gtaaa|tttac[agt]ct/i
18 R/ agg[act]taaa|ttta[agt]cct/i
19 R/ aggg[acg]aaa|ttt[cgt]ccct/i
20 R/ agggt[cgt]aa|tt[acg]accct/i
21 R/ agggta[cgt]a|t[acg]taccct/i
22 R/ agggtaa[cgt]|[acg]ttaccct/i
29 : do-replacements ( string -- string' )
42 } [ re-replace ] assoc-each ;
47 : regex-dna ( file -- )
48 ascii file-contents dup length ilen set
49 strip-line-breaks dup length clen set
57 : regex-dna-main ( -- )
58 "resource:extra/benchmark/regex-dna/regex-dna-test-in.txt" regex-dna ;