]> gitweb.factorcode.org Git - factor.git/blob - extra/tools/time/time.factor
Merge branch 'master' of git://factorcode.org/git/factor
[factor.git] / extra / tools / time / time.factor
1 ! Copyright (C) 2003, 2008 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: kernel math math.vectors memory io io.styles prettyprint
4 namespaces system sequences splitting grouping assocs strings ;
5 IN: tools.time
6
7 : benchmark ( quot -- runtime )
8     millis >r call millis r> - ; inline
9
10 : simple-table. ( values -- )
11     standard-table-style [
12         [
13             [
14                 [
15                     dup string?
16                     [ [ write ] with-cell ]
17                     [ pprint-cell ]
18                     if
19                 ] each
20             ] with-row
21         ] each
22     ] tabular-output ;
23
24 : time. ( data -- )
25     unclip
26     "==== RUNNING TIME" print nl pprint " ms" print nl
27     4 cut*
28     "==== GARBAGE COLLECTION" print nl
29     [
30         6 group
31         {
32             "GC count:"
33             "Cumulative GC time (ms):"
34             "Longest GC pause (ms):"
35             "Average GC pause (ms):"
36             "Objects copied:"
37             "Bytes copied:"
38         } prefix
39         flip
40         { "" "Nursery" "Aging" "Tenured" } prefix
41         simple-table.
42     ]
43     [
44         nl
45         {
46             "Total GC time (ms):"
47             "Cards scanned:"
48             "Decks scanned:"
49             "Code heap literal scans:"
50         } swap zip simple-table.
51     ] bi* ;
52
53 : time ( quot -- )
54     gc-reset millis >r call gc-stats millis r> - prefix time. ; inline