factor/basis/tools/time/time.factor

39 lines
1.1 KiB
Factor
Raw Normal View History

2009-10-27 04:37:05 -04:00
! Copyright (C) 2003, 2009 Slava Pestov.
2007-09-20 18:09:08 -04:00
! See http://factorcode.org/license.txt for BSD license.
USING: kernel math memory io io.styles prettyprint
namespaces system sequences splitting grouping assocs strings
generic.single combinators ;
2007-09-20 18:09:08 -04:00
IN: tools.time
: benchmark ( quot -- runtime )
2008-12-03 09:46:16 -05:00
micros [ call micros ] dip - ; inline
2008-05-07 18:42:41 -04:00
: time. ( time -- )
"== Running time ==" print nl 1000000 /f pprint " seconds" print ;
: dispatch-stats. ( stats -- )
"== Megamorphic caches ==" print nl
[ { "Hits" "Misses" } ] dip zip simple-table. ;
: inline-cache-stats. ( stats -- )
2009-10-27 04:37:05 -04:00
"== Polymorphic inline caches ==" print nl
3 cut
[
2009-10-27 04:37:05 -04:00
"- Transitions:" print
[ { "Cold to monomorphic" "Mono to polymorphic" "Poly to megamorphic" } ] dip zip
simple-table. nl
] [
2009-10-27 04:37:05 -04:00
"- Type check stubs:" print
[ { "Tag" "Tuple" } ] dip zip
simple-table.
] bi* ;
2007-09-20 18:09:08 -04:00
: time ( quot -- )
reset-dispatch-stats
reset-inline-cache-stats
2009-10-27 04:37:05 -04:00
benchmark dispatch-stats inline-cache-stats
[ time. nl ]
[ dispatch-stats. nl ]
[ inline-cache-stats. ]
tri* ; inline