1# bench_wtext.tcl --
2#
3#	Management of benchmarks, formatted text.
4#
5# Copyright (c) 2005 by Andreas Kupries <andreas_kupries@users.sourceforge.net>
6# library derived from runbench.tcl application (C) Jeff Hobbs.
7#
8# See the file "license.terms" for information on usage and redistribution
9# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
10#
11# RCS: @(#) $Id: bench_wcsv.tcl,v 1.4 2007/01/21 23:29:06 andreas_kupries Exp $
12
13# ### ### ### ######### ######### ######### ###########################
14## Requisites - Packages and namespace for the commands and data.
15
16package require Tcl 8.2
17package require csv
18
19namespace eval ::bench::out {}
20
21# ### ### ### ######### ######### ######### ###########################
22## Public API - Benchmark execution
23
24# ### ### ### ######### ######### ######### ###########################
25## Public API - Result formatting.
26
27# ::bench::out::csv --
28#
29#	Format the result of a benchmark run.
30#	Style: CSV
31#
32# Arguments:
33#	DATA dict
34#
35# Results:
36#	String containing the formatted DATA.
37
38proc ::bench::out::csv {data} {
39    array set DATA $data
40    set CSV {}
41
42    # 1st record:              #shells
43    # 2nd record to #shells+1: Interpreter data (id, version, path)
44    # #shells+2 to end:        Benchmark data (id,desc,result1,...,result#shells)
45
46    # --- --- ----
47    # #interpreters used
48
49    set ipkeys [array names DATA interp*]
50    lappend CSV [csv::join [list [llength $ipkeys]]]
51
52    # --- --- ----
53    # Table 1: Interpreter information.
54
55    set n 1
56    set iplist {}
57    foreach key [lsort -dict $ipkeys] {
58	set ip [lindex $key 1]
59	lappend CSV [csv::join [list $n $DATA($key) $ip]]
60	set DATA($key) $n
61	incr n
62	lappend iplist $ip
63    }
64
65    # --- --- ----
66    # Table 2: Benchmark information
67
68    set dlist {}
69    foreach key [lsort -dict -index 1 [array names DATA desc*]] {
70	lappend dlist [lindex $key 1]
71    }
72
73    set n 1
74    foreach desc $dlist {
75	set record {}
76	lappend record $n
77	lappend record $desc
78	foreach ip $iplist {
79	    if {[catch {
80		lappend record $DATA([list usec $desc $ip])
81	    }]} {
82		lappend record {}
83	    }
84	}
85	lappend CSV [csv::join $record]
86	incr n
87    }
88
89    return [join $CSV \n]
90}
91
92# ### ### ### ######### ######### ######### ###########################
93## Internal commands
94
95# ### ### ### ######### ######### ######### ###########################
96## Initialize internal data structures.
97
98# ### ### ### ######### ######### ######### ###########################
99## Ready to run
100
101package provide bench::out::csv 0.1.2
102