Fix tools.time output in the TTY listener

db4
Slava Pestov 2009-04-30 20:03:52 -05:00
parent b20ed595c4
commit f51b7b2677
4 changed files with 34 additions and 16 deletions

View File

@ -99,7 +99,11 @@ M: plain-writer make-block-stream
nip <ignore-close-stream> ; nip <ignore-close-stream> ;
M: plain-writer stream-write-table M: plain-writer stream-write-table
[ drop format-table [ nl ] [ write ] interleave ] with-output-stream* ; [
drop
[ [ >string ] map ] map format-table
[ nl ] [ write ] interleave
] with-output-stream* ;
M: plain-writer make-cell-stream 2drop <string-writer> ; M: plain-writer make-cell-stream 2drop <string-writer> ;

View File

@ -2,3 +2,7 @@
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: tools.test strings.tables ; USING: tools.test strings.tables ;
IN: strings.tables.tests IN: strings.tables.tests
[ { "A BB" "CC D" } ] [ { { "A" "BB" } { "CC" "D" } } format-table ] unit-test
[ { "A C" "B " "D E" } ] [ { { "A\nB" "C" } { "D" "E" } } format-table ] unit-test

View File

@ -1,21 +1,30 @@
! Copyright (C) 2009 Slava Pestov. ! Copyright (C) 2009 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: kernel sequences fry math.order ; USING: kernel sequences fry math.order splitting ;
IN: strings.tables IN: strings.tables
<PRIVATE <PRIVATE
: format-column ( seq ? -- seq )
[
dup [ length ] [ max ] map-reduce
'[ _ CHAR: \s pad-tail ] map
] unless ;
: map-last ( seq quot -- seq ) : map-last ( seq quot -- seq )
[ dup length <reversed> ] dip '[ 0 = @ ] 2map ; inline [ dup length <reversed> ] dip '[ 0 = @ ] 2map ; inline
: max-length ( seq -- n )
[ length ] [ max ] map-reduce ;
: format-row ( seq ? -- seq )
[
dup max-length
'[ _ "" pad-tail ] map
] unless ;
: format-column ( seq ? -- seq )
[
dup max-length
'[ _ CHAR: \s pad-tail ] map
] unless ;
PRIVATE> PRIVATE>
: format-table ( table -- seq ) : format-table ( table -- seq )
flip [ format-column ] map-last [ [ [ string-lines ] map ] dip format-row flip ] map-last concat
flip [ " " join ] map ; flip [ format-column ] map-last flip [ " " join ] map ;

View File

@ -9,18 +9,19 @@ IN: tools.time
micros [ call micros ] dip - ; inline micros [ call micros ] dip - ; inline
: time. ( time -- ) : time. ( time -- )
"== Running time ==" print nl 1000000 /f pprint " seconds" write ; "== Running time ==" print nl 1000000 /f pprint " seconds" print ;
: gc-stats. ( stats -- ) : gc-stats. ( stats -- )
5 cut* 5 cut*
"== Garbage collection ==" print nl "== Garbage collection ==" print nl
"Times are in microseconds." print nl
[ [
6 group 6 group
{ {
"GC count:" "GC count:"
"Cumulative GC time (us):" "Total GC time:"
"Longest GC pause (us):" "Longest GC pause:"
"Average GC pause (us):" "Average GC pause:"
"Objects copied:" "Objects copied:"
"Bytes copied:" "Bytes copied:"
} prefix } prefix
@ -31,10 +32,10 @@ IN: tools.time
[ [
nl nl
{ {
"Total GC time (us):" "Total GC time:"
"Cards scanned:" "Cards scanned:"
"Decks scanned:" "Decks scanned:"
"Card scan time (us):" "Card scan time:"
"Code heap literal scans:" "Code heap literal scans:"
} swap zip simple-table. } swap zip simple-table.
] bi* ; ] bi* ;