zlib: Don't use PASTE for INTMAX error messages
[jimtcl.git] / tests / perf.test
blob145f432eb583187fa6f2c9f30b78e2cc3241b02b
1 source [file dirname [info script]]/testing.tcl
3 needs constraint manual
5 set iterations 10000
7 set version [info patchlevel]
9 proc bench {name cmd} {
10         if {[catch {
11                 set t [time $cmd 2]
12                 set ms [format %.0f [expr {[lindex $t 0] / 1000}]]
13         }]} {
14                 set ms ?
15         }
16         puts "$::version: $name ${ms}ms"
19 proc set_dict_sugar {} {
20         for {set i 0} {$i < $::iterations} {incr i} {
21                 set a(b) $i
22         }
25 # Note that this case does not benefit from the dict sugar
26 # speedup since a($b) needs to be interpolated and reparsed every time
27 proc set_var_dict_sugar {} {
28         set b b
29         for {set i 0} {$i < $::iterations} {incr i} {
30                 set a($b) $i
31         }
34 proc set_var_dict {} {
35         set b b
36         for {set i 0} {$i < $::iterations} {incr i} {
37                 dict set a $b $i
38         }
41 proc read_file {file} {
42         set f [open $file]
43         while {[gets $f buf] >= 0} {
44         }
45         close $f
48 proc read_file_split {file} {
49         set f [open $file]
50         while {[gets $f buf] >= 0} {
51                 split $buf \t
52         }
53         close $f
56 proc read_file_split_assign_foreach {file} {
57         set f [open $file]
58         while {[gets $f buf] >= 0} {
59                 foreach {info(chan) info(datetime) info(duration) info(title) subtitle_genre info(desc) info(rating) dummy} [split $buf \t] {break}
60         }
61         close $f
64 proc read_file_split_assign_foreach_dict {file} {
65         set f [open $file]
66         while {[gets $f buf] >= 0} {
67                 foreach {chan datetime duration title subtitle_genre desc rating dummy} [split $buf \t] {break}
68                 dict set info chan $chan
69                 dict set info duration $duration
70                 dict set info title $title
71                 dict set info subtitle_genre $subtitle_genre
72                 dict set info desc $desc
73                 dict set info rating $rating
74         }
75         close $f
78 proc read_file_split_assign_foreach_dictsugar {file} {
79         set f [open $file]
80         while {[gets $f buf] >= 0} {
81                 foreach {chan datetime duration title subtitle_genre desc rating dummy} [split $buf \t] {break}
82                 set info(chan) $chan
83                 set info(duration) $duration
84                 set info(title) $title
85                 set info(subtitle_genre) $subtitle_genre
86                 set info(desc) $desc
87                 set info(rating) $rating
88         }
89         close $f
92 proc read_file_split_assign_foreach_simple {file} {
93         set f [open $file]
94         while {[gets $f buf] >= 0} {
95                 foreach {chan datetime duration title subtitle_genre desc rating dummy} [split $buf \t] {break}
96         }
97         close $f
100 proc read_file_split_assign_lindex {file} {
101         set f [open $file]
102         while {[gets $f buf] >= 0} {
103                 set split [split $buf \t]
104                 set info(chan) [lindex $split 0]
105                 set info(datetime) [lindex $split 1]
106                 set info(duration) [lindex $split 2]
107                 set info(title) [lindex $split 3]
108                 set info(subtitle_genre) [lindex $split 4]
109                 set info(desc) [lindex $split 5]
110                 set info(rating) [lindex $split 6]
111         }
112         close $f
115 # Create a really big file
116 set f [open test.in w]
117 for {set i 0} {$i < $::iterations} {incr i} {
118         puts $f "a\tb\tc\te\tf\tg\th\ti\tj\tk"
120 close $f
122 bench "set dictsugar" {set_dict_sugar}
123 bench "set var dictsugar" {set_var_dict_sugar}
124 bench "set var dict" {set_var_dict}
125 # Read once before testing perf
126 read_file test.in
127 bench "read file" {read_file test.in}
128 bench "read file split" {read_file_split test.in}
129 bench "foreach: simple" {read_file_split_assign_foreach_simple test.in}
130 bench "foreach: direct dictsugar" {read_file_split_assign_foreach test.in}
131 bench "foreach: dict cmd" {read_file_split_assign_foreach_dict test.in}
132 bench "foreach: assign to dictsugar" {read_file_split_assign_foreach_dictsugar test.in}
133 bench "foreach: assign to dictsugar via lindex" {read_file_split_assign_lindex test.in}
135 file delete test.in
137 # testreport