]> gitweb.factorcode.org Git - factor.git/blobdiff - extra/benchmark/knucleotide/knucleotide.factor
factor: trim using lists
[factor.git] / extra / benchmark / knucleotide / knucleotide.factor
index 4e4ec722715646f978dacb0388bff3cf19cd1dc2..2ba6b433cf2e6cb02097f821d822db55c3c9cff6 100644 (file)
@@ -1,9 +1,11 @@
-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* ;
@@ -14,15 +16,15 @@ IN: benchmark.knucleotide
     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 ]
@@ -33,9 +35,9 @@ IN: benchmark.knucleotide
     ]
     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