]> gitweb.factorcode.org Git - factor.git/blob - extra/benchmark/benchmark.factor
Merge branch 'master' into experimental
[factor.git] / extra / benchmark / benchmark.factor
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
7
8 : run-benchmark ( vocab -- result )
9     [ "=== " write vocab-name print flush ] [
10         [ [ require ] [ [ run ] benchmark ] bi ] curry
11         [ error. f ] recover
12     ] bi ;
13
14 : run-benchmarks ( -- assoc )
15     "benchmark" all-child-vocabs-seq
16     [ dup run-benchmark ] { } map>assoc ;
17
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 ] with-cell ] if* ] bi*
28             ] with-row
29         ] assoc-each
30     ] tabular-output nl ;
31
32 : benchmarks ( -- )
33     run-benchmarks benchmarks. ;
34
35 MAIN: benchmarks
36