factor/basis/tools/time/time.factor

74 lines
2.0 KiB
Factor
Raw Normal View History

2008-05-07 18:42:41 -04:00
! Copyright (C) 2003, 2008 Slava Pestov.
2007-09-20 18:09:08 -04:00
! See http://factorcode.org/license.txt for BSD license.
2008-05-07 18:42:41 -04:00
USING: kernel math math.vectors 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" write ;
: gc-stats. ( stats -- )
5 cut*
"== Garbage collection ==" print nl
2008-05-08 00:09:18 -04:00
[
6 group
{
"GC count:"
"Cumulative GC time (us):"
"Longest GC pause (us):"
"Average GC pause (us):"
2008-05-08 00:09:18 -04:00
"Objects copied:"
"Bytes copied:"
} prefix
flip
{ "" "Nursery" "Aging" "Tenured" } prefix
simple-table.
]
[
nl
{
2008-11-23 04:26:31 -05:00
"Total GC time (us):"
2008-05-08 00:09:18 -04:00
"Cards scanned:"
"Decks scanned:"
"Card scan time (us):"
2008-05-08 00:09:18 -04:00
"Code heap literal scans:"
} swap zip simple-table.
] bi* ;
2007-09-20 18:09:08 -04:00
: dispatch-stats. ( stats -- )
"== Megamorphic caches ==" print nl
{ "Hits" "Misses" } swap zip simple-table. ;
: inline-cache-stats. ( stats -- )
nl "== Polymorphic inline caches ==" print nl
3 cut
[
"Transitions:" print
{ "Cold to monomorphic" "Mono to polymorphic" "Poly to megamorphic" } swap zip
simple-table. nl
] [
"Type check stubs:" print
{ "Tag only" "Hi-tag" "Tuple" "Hi-tag and tuple" } swap zip
simple-table.
] bi* ;
2007-09-20 18:09:08 -04:00
: time ( quot -- )
gc-reset
reset-dispatch-stats
reset-inline-cache-stats
benchmark gc-stats dispatch-stats inline-cache-stats
H{ { table-gap { 20 20 } } } [
[
[ [ time. ] 3dip ] with-cell
[ ] with-cell
] with-row
[
[ [ gc-stats. ] 2dip ] with-cell
[ [ dispatch-stats. ] [ inline-cache-stats. ] bi* ] with-cell
] with-row
] tabular-output nl ; inline