Merge branch 'master' of git://factorcode.org/git/factor
[factor/jcg.git] / extra / benchmark / benchmark.factor
blob9afd2118766d9bebf382683e8797e4d07feb945a
1 ! Copyright (C) 2007, 2008 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: kernel vocabs vocabs.loader tools.time tools.vocabs
4 arrays assocs io.styles io help.markup prettyprint sequences
5 continuations debugger math ;
6 IN: benchmark
8 : run-benchmark ( vocab -- result )
9     [ "=== " write vocab-name print flush ] [
10         [ [ require ] [ [ run ] benchmark ] bi ] curry
11         [ error. f ] recover
12     ] bi ;
14 : run-benchmarks ( -- assoc )
15     "benchmark" all-child-vocabs-seq
16     [ dup run-benchmark ] { } map>assoc ;
18 : benchmarks. ( assoc -- )
19     standard-table-style [
20         [
21             [ "Benchmark" write ] with-cell
22             [ "Time (seconds)" write ] with-cell
23         ] with-row
24         [
25             [
26                 [ [ 1array $vocab-link ] with-cell ]
27                 [ [ 1000000 /f pprint-cell ] [ "failed" write ] if* ] bi*
28             ] with-row
29         ] assoc-each
30     ] tabular-output ;
32 : benchmarks ( -- )
33     run-benchmarks benchmarks. ;
35 MAIN: benchmarks