benchmark: refactoring to not use dynamic variables + unit tests
parent
119f188423
commit
a738c356a0
|
@ -0,0 +1,17 @@
|
||||||
|
USING: benchmark kernel sequences tools.test ;
|
||||||
|
IN: benchmark.tests
|
||||||
|
|
||||||
|
: dummy-benchmark ( -- )
|
||||||
|
;
|
||||||
|
|
||||||
|
MAIN: dummy-benchmark
|
||||||
|
|
||||||
|
{ "benchmark.tests" } [
|
||||||
|
{ "benchmark.tests" } [ run-timing-benchmark ] run-benchmarks
|
||||||
|
drop first first
|
||||||
|
] unit-test
|
||||||
|
|
||||||
|
{ 0 1 } [
|
||||||
|
{ "benchmark.tests" } [ drop "hello" throw ] run-benchmarks
|
||||||
|
[ length ] bi@
|
||||||
|
] unit-test
|
|
@ -1,60 +1,40 @@
|
||||||
! Copyright (C) 2007, 2009 Slava Pestov.
|
! Copyright (C) 2007, 2009 Slava Pestov.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: arrays assocs continuations debugger fry help.markup io
|
USING: arrays assocs continuations debugger formatting fry help.markup
|
||||||
io.styles kernel math memory namespaces prettyprint sequences
|
io io.styles kernel math memory prettyprint sequences
|
||||||
tools.profiler.sampling tools.time vocabs vocabs.hierarchy
|
tools.profiler.sampling tools.time vocabs.hierarchy vocabs.loader ;
|
||||||
vocabs.loader ;
|
|
||||||
IN: benchmark
|
IN: benchmark
|
||||||
|
|
||||||
<PRIVATE
|
|
||||||
|
|
||||||
SYMBOL: results
|
|
||||||
SYMBOL: errors
|
|
||||||
|
|
||||||
PRIVATE>
|
|
||||||
|
|
||||||
: run-timing-benchmark ( vocab -- time )
|
: run-timing-benchmark ( vocab -- time )
|
||||||
[ 5 ] dip '[ gc [ _ run ] benchmark ] replicate infimum ;
|
5 swap '[ gc [ _ run ] benchmark ] replicate infimum ;
|
||||||
|
|
||||||
: run-profile-benchmark ( vocab -- profile )
|
: run-profile-benchmark ( vocab -- profile )
|
||||||
compact-gc '[ _ run ] profile most-recent-profile-data ;
|
compact-gc '[ _ run ] profile most-recent-profile-data ;
|
||||||
|
|
||||||
: find-benchmark-vocabs ( -- seq )
|
: find-benchmark-vocabs ( -- seq )
|
||||||
"benchmark" disk-child-vocab-names
|
"benchmark" disk-child-vocab-names [ find-vocab-root ] filter ;
|
||||||
[ find-vocab-root ] filter ;
|
|
||||||
|
|
||||||
<PRIVATE
|
<PRIVATE
|
||||||
|
|
||||||
: print-record-header ( vocab -- )
|
: write-header ( str -- )
|
||||||
"=== " write print flush ;
|
"=== %s\n" printf ;
|
||||||
|
|
||||||
: run-benchmark ( vocab quot -- )
|
: run-benchmark ( vocab quot: ( vocab -- res ) -- result ok? )
|
||||||
[ drop print-record-header ] [
|
over write-header '[ _ @ t ] [ f ] recover ; inline
|
||||||
'[
|
|
||||||
_ [ [ require ] _ [ ] tri results ]
|
|
||||||
[ swap errors ]
|
|
||||||
recover get set-at
|
|
||||||
] call
|
|
||||||
] 2bi ; inline
|
|
||||||
|
|
||||||
: run-benchmarks ( quot -- results errors )
|
|
||||||
'[
|
|
||||||
results errors
|
|
||||||
[ [ V{ } clone swap set ] bi@ ]
|
|
||||||
[ 2drop find-benchmark-vocabs [ _ run-benchmark ] each ]
|
|
||||||
[ [ get ] bi@ ]
|
|
||||||
2tri
|
|
||||||
] with-scope ; inline
|
|
||||||
|
|
||||||
PRIVATE>
|
PRIVATE>
|
||||||
|
|
||||||
: run-timing-benchmarks ( -- results errors )
|
: run-benchmarks ( benchmarks quot: ( vocab -- res ) -- results errors )
|
||||||
[ run-timing-benchmark ] run-benchmarks ;
|
'[ dup _ run-benchmark 3array ] map
|
||||||
|
[ third ] partition [ [ 2 head ] map ] bi@ ; inline
|
||||||
|
|
||||||
: run-profile-benchmarks ( -- results errors )
|
: run-profile-benchmarks ( -- results errors )
|
||||||
[ run-profile-benchmark ] run-benchmarks ;
|
find-benchmark-vocabs [ run-profile-benchmark ] run-benchmarks ;
|
||||||
|
|
||||||
: timings. ( assocs -- )
|
: run-timing-benchmarks ( -- results errors )
|
||||||
|
find-benchmark-vocabs [ run-timing-benchmark ] run-benchmarks ;
|
||||||
|
|
||||||
|
: timings. ( assoc -- )
|
||||||
standard-table-style [
|
standard-table-style [
|
||||||
[
|
[
|
||||||
[ "Benchmark" write ] with-cell
|
[ "Benchmark" write ] with-cell
|
||||||
|
@ -69,15 +49,12 @@ PRIVATE>
|
||||||
] assoc-each
|
] assoc-each
|
||||||
] tabular-output nl ;
|
] tabular-output nl ;
|
||||||
|
|
||||||
: benchmark-errors. ( errors -- )
|
: benchmark-errors. ( assoc -- )
|
||||||
[
|
[
|
||||||
[ "=== " write vocab-name print ]
|
[ write-header ] [ error. ] bi*
|
||||||
[ error. ]
|
|
||||||
bi*
|
|
||||||
] assoc-each ;
|
] assoc-each ;
|
||||||
|
|
||||||
: timing-benchmarks ( -- )
|
: timing-benchmarks ( -- )
|
||||||
run-timing-benchmarks
|
run-timing-benchmarks [ timings. ] [ benchmark-errors. ] bi* ;
|
||||||
[ timings. ] [ benchmark-errors. ] bi* ;
|
|
||||||
|
|
||||||
MAIN: timing-benchmarks
|
MAIN: timing-benchmarks
|
||||||
|
|
Loading…
Reference in New Issue