1 source [file dirname [info script]]/testing.tcl
3 needs constraint manual
7 set version [info patchlevel]
9 proc bench {name cmd} {
12 set ms [format %.0f [expr {[lindex $t 0] / 1000}]]
16 puts "$::version: $name ${ms}ms"
19 proc set_dict_sugar {} {
20 for {set i 0} {$i < $::iterations} {incr i} {
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 {} {
29 for {set i 0} {$i < $::iterations} {incr i} {
34 proc set_var_dict {} {
36 for {set i 0} {$i < $::iterations} {incr i} {
41 proc read_file {file} {
43 while {[gets $f buf] >= 0} {
48 proc read_file_split {file} {
50 while {[gets $f buf] >= 0} {
56 proc read_file_split_assign_foreach {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}
64 proc read_file_split_assign_foreach_dict {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
78 proc read_file_split_assign_foreach_dictsugar {file} {
80 while {[gets $f buf] >= 0} {
81 foreach {chan datetime duration title subtitle_genre desc rating dummy} [split $buf \t] {break}
83 set info(duration) $duration
84 set info(title) $title
85 set info(subtitle_genre) $subtitle_genre
87 set info(rating) $rating
92 proc read_file_split_assign_foreach_simple {file} {
94 while {[gets $f buf] >= 0} {
95 foreach {chan datetime duration title subtitle_genre desc rating dummy} [split $buf \t] {break}
100 proc read_file_split_assign_lindex {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]
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"
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
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}