1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
|
package require Tcl 8.5
package require bench::in
package require struct::matrix
package require report
proc main {} {
write [calc [input 0]] [calc [input 1]]
}
proc input {n} {
global argv
set thefile [file join [file dirname [file dirname [file normalize [info script]]]] \
tests data ok peg_peg-fused 3_peg_itself]
set chars [file size $thefile]
set benchdata [bench::in::read [lindex $argv $n]]
#array set DATA $benchdata
#parray DATA
return [list $chars $benchdata]
}
proc calc {data} {
lassign $data chars benchdata
array set BENCH $benchdata
set res {}
set n 1
foreach key [lsort -dict [array names BENCH usec*]] {
lassign $key _ desc interp
set useconds $BENCH($key)
set seconds [expr {double($useconds)/1000000}]
set charsec [expr {$chars/$seconds}]
set usecchar [expr {$useconds/double($chars)}]
lappend res [list $n $desc \
[format %.2f $useconds] \
[format %.2f $seconds] \
[format %.2f $charsec] \
[format %.2f $usecchar] \
]
incr n
}
return [list $chars $res]
}
proc write {base new} {
global argv
lassign $base chars benchbase
lassign $new chars benchnew
lassign $argv base new
::struct::matrix M
M add columns 6
::report::report R 6 style dcaptionedtable 2 4
R pad 0 both " " ; R justify 0 center
R pad 1 both " " ; R justify 1 left
R pad 2 both " " ; R justify 2 right
R pad 3 both " " ; R justify 3 right
R pad 4 both " " ; R justify 4 right
R pad 5 both " " ; R justify 5 right
M add row [list {} {} $base $new {} {}]
M add row [list {} "INPUT $chars chars" chars/sec chars/sec x %]
lassign $benchbase a b c d e f g ; set benchbase [list $c $b $a $g $f $e $d]
lassign $benchnew a b c d e f g ; set benchnew [list $c $b $a $g $f $e $d]
foreach base $benchbase new $benchnew {
lassign $base n desc usecbase _ csbase _
lassign $new _ _ usecnew _ csnew _
set factor [expr {double($usecbase)/double($usecnew)}]
set percent [expr {100 * $factor - 100}]
M add row [list $n $desc $csbase $csnew \
[format %.2f $factor] \
[format %.2f $percent] \
]
}
puts [M format 2string R]
return
}
::report::defstyle simpletable {} {
data set [split "[string repeat "| " [columns]]|"]
top set [split "[string repeat "+ - " [columns]]+"]
bottom set [top get]
top enable
bottom enable
}
::report::defstyle captionedtable {{n 1}} {
simpletable
topdata set [data get]
topcapsep set [top get]
topcapsep enable
tcaption $n
}
::report::defstyle dcaptionedtable {{t 1} {b 1}} {
simpletable
topdata set [data get]
topcapsep set [top get]
topcapsep enable
botdata set [data get]
botcapsep set [top get]
botcapsep enable
tcaption $t
bcaption $b
}
main
exit
|