-USING: ascii kernel io io.files splitting strings
-io.encodings.ascii hashtables sequences assocs math
-math.statistics namespaces prettyprint math.parser combinators
-arrays sorting formatting grouping fry ;
+! Copyright (C) 2008, 2010 Slava Pestov.
+! See http://factorcode.org/license.txt for BSD license.
+USING: ascii assocs formatting grouping io io.encodings.ascii
+io.files kernel math math.statistics sequences ;
IN: benchmark.knucleotide
+CONSTANT: knucleotide-in "vocab:benchmark/knucleotide/knucleotide-input.txt"
+
: discard-lines ( -- )
readln
[ ">THREE" head? [ discard-lines ] unless ] when* ;
CHAR: \n swap remove >upper ;
: handle-table ( inputs n -- )
- <clumps>
- [ histogram >alist sort-values reverse ] [ length ] bi
+ clump
+ [ sorted-histogram reverse ] [ length ] bi
'[
[ first write bl ]
[ second 100 * _ /f "%.3f" printf nl ] bi
] each ;
: handle-n ( input x -- )
- [ nip ] [ length <clumps> histogram ] 2bi at 0 or "%d\t" printf ;
+ [ nip ] [ length clump histogram ] 2bi at 0 or "%d\t" printf ;
: process-input ( input -- )
[ 1 handle-table nl ]
]
tri ;
-: knucleotide ( -- )
- "resource:extra/benchmark/knucleotide/knucleotide-input.txt"
+: knucleotide-benchmark ( -- )
+ knucleotide-in
ascii [ read-input ] with-file-reader
process-input ;
-MAIN: knucleotide
+MAIN: knucleotide-benchmark