1# all-bench.tcl --
2#
3# This file contains the top-level script to run the tDOM bench mark
4# suite.
5#
6# Copyright (c) 2007 by Rolf Ade (rolf@pointsman.de).
7#
8# $Id: all-bench.tcl,v 1.1 2007/09/27 23:17:02 rolf Exp $
9#
10# The script knows the options:
11#
12# -interppath <dir-path>
13# Adds a path to the list of pathes, which are searched for tclshs
14# with the pattern given by the -pattern option. Every time, this
15# option is given, the option value is added to the search list. If
16# not given, it is set to directory the tclsh, running the script,
17# lives in.
18#
19# -norm <number>
20# See man bench, ::bench::norm
21#
22# -pattern <pattern>
23# Specifies the search pattern for tclshs in the search
24# directories. Defaults to tclsh*
25#
26# -file <pattern>
27# Specifies the search pattern for bench files in the same directory
28# as the all-bench.tcl. The default is *.bench.
29#
30# Every known option to ::bench::run (as of 0.3.1) are passed throu to
31# that command. See man bench for the details.
32#
33# Example:
34# tclsh all-bench.tcl \
35#     -interppath /usr/local/lib \
36#     -pkgdir ~/tdom/tdom-0.8.2 \
37#     -pkgdir ~/tdom/tdom-0.8.2-mod
38#
39# You can measure the same tDOM version against various tclshs, or
40# different tDOM versions with the same tclsh, or different tDOM
41# versions with differenct tclshs, all side by side.
42#
43# Don't run this script with a tcldomsh, until you know, what you're
44# doing.
45
46# bench 0.3.1 added the -pkgdir flag; we need at least that version,
47# if we want to compare more than one tDOM versions side by side.
48package require bench 0.3.1
49package require bench::out::text
50
51
52# Defaults / Initialization
53set interpPattern tclsh*
54set benchFilePattern *.bench
55set interpPaths [list]
56set benchFlags [list]
57# Empty string means: no normalization
58set norm ""
59
60foreach {arg argValue} $argv {
61    switch -- $arg {
62        "-interppath" {
63            lappend interpPaths $argValue
64        }
65        "-norm" {
66            if {![string is integer -strict $argValue] || $argValue < 1} {
67                puts stderr "The option -norm expects a postiv integer as\
68                             value."
69                exit 1
70            }
71            set norm $argValue
72        }
73        "-pattern" {
74            set interpPattern $argValue
75        }
76        "-file" {
77            set benchFilePattern $argValue
78        }
79        default {
80            switch -- $arg {
81                "-errors" -
82                "-threads" -
83                "-match" -
84                "-rmatch" -
85                "-iters" -
86                "-pkgdir" {
87                    lappend benchFlags $arg $argValue
88                }
89                default {
90                    puts stderr "Unknown option '$arg'"
91                    exit 1
92                }
93            }
94        }
95    }
96}
97
98
99if {[llength $interpPaths] == 0} {
100    lappend interpPaths [file dirname [info nameofexecutable]]
101    puts $interpPaths
102}
103
104puts [bench::locate $interpPattern $interpPaths]
105
106set interps [bench::versions [bench::locate $interpPattern $interpPaths]]
107
108if {![llength $interps]} {
109    puts stderr "No interpreters found"
110    exit 1
111}
112
113if {[llength $benchFlags]} {
114    set cmd [linsert $benchFlags 0 bench::run]
115} else {
116    set cmd [list bench::run]
117}
118
119set benchfiles [glob -nocomplain [file join [file dir [info script]] \
120                                      $benchFilePattern]]
121if {![llength $benchfiles]} {
122    puts stderr "No benchmark files found."
123    exit 1
124}
125
126set run $cmd
127lappend run $interps $benchfiles
128set results [eval $run]
129if {$norm ne ""} {
130    set results [::bench::norm $results $norm]
131}
132puts [::bench::out::text $results]
133