bench_wtext.tcl

Go to the documentation of this file.
00001 /*  bench_wtext.tcl --*/
00002 /* */
00003 /*  Management of benchmarks, formatted text.*/
00004 /* */
00005 /*  Copyright (c) 2005 by Andreas Kupries <andreas_kupries@users.sourceforge.net>*/
00006 /*  library derived from runbench.tcl application (C) Jeff Hobbs.*/
00007 /* */
00008 /*  See the file "license.terms" for information on usage and redistribution*/
00009 /*  of this file, and for a DISCLAIMER OF ALL WARRANTIES.*/
00010 /*  */
00011 /*  RCS: @(#) $Id: bench_wtext.tcl,v 1.4 2007/01/21 23:29:06 andreas_kupries Exp $*/
00012 
00013 /*  ### ### ### ######### ######### ######### ###########################*/
00014 /*  Requisites - Packages and namespace for the commands and data.*/
00015 
00016 package require Tcl 8.2
00017 package require struct::matrix
00018 package require report
00019 
00020 namespace ::bench::out {}
00021 
00022 /*  ### ### ### ######### ######### ######### ###########################*/
00023 /*  Public API - Result formatting.*/
00024 
00025 /*  ::bench::out::text --*/
00026 /* */
00027 /*  Format the result of a benchmark run.*/
00028 /*  Style: TEXT*/
00029 /* */
00030 /*  General structure like CSV, but nicely formatted and aligned*/
00031 /*  columns.*/
00032 /* */
00033 /*  Arguments:*/
00034 /*  DATA dict*/
00035 /* */
00036 /*  Results:*/
00037 /*  String containing the formatted DATA.*/
00038 
00039 ret  ::bench::out::text (type data) {
00040     array set DATA $data
00041     set LINES {}
00042 
00043     # 1st line to #shells: Interpreter data (id, version, path)
00044     # #shells+1 to end:    Benchmark data (id,desc,result1,...,result#shells)
00045 
00046     lappend LINES {}
00047 
00048     # --- --- ----
00049     # Table 1: Interpreter information.
00050 
00051     set ipkeys [array names DATA interp*]
00052     set n 1
00053     set iplist {}
00054     set vlen 0
00055     foreach key [lsort -dict $ipkeys] {
00056     lappend iplist [lindex $key 1]
00057     incr n
00058     set l [string length $DATA($key)]
00059     if {$l > $vlen} {set vlen $l}
00060     }
00061     set idlen [string length $n]
00062 
00063     set dlist {}
00064     set n 1
00065     foreach key [lsort -dict -index 1 [array names DATA desc*]] {
00066     lappend dlist [lindex $key 1]
00067     incr n
00068     }
00069     set didlen [string length $n]
00070 
00071     set n 1
00072     set record [list "" INTERP]
00073     foreach ip $iplist {
00074     set v $DATA([list interp $ip])
00075     lappend LINES " [PADL $idlen $n]: [PADR $vlen $v] $ip"
00076     lappend record $n
00077     incr n
00078     }
00079 
00080     lappend LINES {}
00081 
00082     # --- --- ----
00083     # Table 2: Benchmark information
00084 
00085     set m [struct::matrix m]
00086     $m add columns [expr {2 + [llength $iplist]}]
00087     $m add row $record
00088 
00089     set n 1
00090     foreach desc $dlist { 
00091     set     record [list $n]
00092     lappend record $desc
00093 
00094     foreach ip $iplist {
00095         if {[catch {
00096         set val $DATA([list usec $desc $ip])
00097         }]} {
00098         set val {}
00099         }
00100         if {[string is double -strict $val]} {
00101         lappend record [format %.2f $val]
00102         } else {
00103         lappend record [format %s   $val]
00104         }
00105     }
00106     $m add row $record
00107     incr n
00108     }
00109 
00110     ::report::defstyle simpletable {} {
00111     data    set [split "[string repeat "| "   [columns]]|"]
00112     top set [split "[string repeat "+ - " [columns]]+"]
00113     bottom  set [top get]
00114     top enable
00115     bottom  enable
00116 
00117     set c [columns]
00118     justify 0 right
00119     pad 0 both
00120 
00121     if {$c > 1} {
00122         justify 1 left
00123         pad 1 both
00124     }
00125     for {set i 2} {$i < $c} {incr i} {
00126         justify $i right
00127         pad $i both
00128     }
00129     }
00130     ::report::defstyle captionedtable {{n 1}} {
00131     simpletable
00132     topdata   set [data get]
00133     topcapsep set [top get]
00134     topcapsep enable
00135     tcaption $n
00136     }
00137 
00138     set r [report::report r [$m columns] style captionedtable]
00139     lappend LINES [$m format 2string $r]
00140     $m destroy
00141     $r destroy
00142 
00143     return [join $LINES \n]
00144 }
00145 
00146 /*  ### ### ### ######### ######### ######### ###########################*/
00147 /*  Internal commands*/
00148 
00149 ret  ::bench::out::PADL (type max , type str) {
00150     format "%${max}s" $str
00151     #return "[PAD $max $str]$str"
00152 }
00153 
00154 ret  ::bench::out::PADR (type max , type str) {
00155     format "%-${max}s" $str
00156     #return "$str[PAD $max $str]"
00157 }
00158 
00159 /*  ### ### ### ######### ######### ######### ###########################*/
00160 /*  Initialize internal data structures.*/
00161 
00162 /*  ### ### ### ######### ######### ######### ###########################*/
00163 /*  Ready to run*/
00164 
00165 package provide bench::out::text 0.1.2
00166 

Generated on 21 Sep 2010 for Gui by  doxygen 1.6.1