]> git.saurik.com Git - redis.git/blob - utils/speed-regression.tcl
speed-regression.tcl script: obtain test names dynamically.
[redis.git] / utils / speed-regression.tcl
1 #!/usr/bin/env tclsh8.5
2 # Copyright (C) 2011 Salvatore Sanfilippo
3 # Released under the BSD license like Redis itself
4
5 proc run-tests branches {
6 set runs {}
7 set branch_id 0
8 foreach b $branches {
9 cd ../src
10 puts "Benchmarking $b"
11 exec -ignorestderr git checkout $b 2> /dev/null
12 exec -ignorestderr make clean 2> /dev/null
13 puts " compiling..."
14 exec -ignorestderr make 2> /dev/null
15
16 if {$branch_id == 0} {
17 puts " copy redis-benchmark from unstable to /tmp..."
18 exec -ignorestderr cp ./redis-benchmark /tmp
19 incr branch_id
20 continue
21 }
22
23 # Start the Redis server
24 puts " starting the server... [exec ./redis-server -v]"
25 set pids [exec echo "port 12123\nloglevel warning\n" | ./redis-server - > /dev/null 2> /dev/null &]
26 after 1000
27 puts " running the benchmark"
28 set output [exec /tmp/redis-benchmark -n 100000 --csv -p 12123]
29 lappend runs $b $output
30 puts " killing server..."
31 catch {
32 exec kill -9 [lindex $pids 0]
33 exec kill -9 [lindex $pids 1]
34 }
35 incr branch_id
36 }
37 return $runs
38 }
39
40 proc get-result-with-name {output name} {
41 foreach line [split $output "\n"] {
42 lassign [split $line ","] key value
43 set key [string tolower [string range $key 1 end-1]]
44 set value [string range $value 1 end-1]
45 if {$key eq [string tolower $name]} {
46 return $value
47 }
48 }
49 return "n/a"
50 }
51
52 proc get-test-names output {
53 set names {}
54 foreach line [split $output "\n"] {
55 lassign [split $line ","] key value
56 set key [string tolower [string range $key 1 end-1]]
57 lappend names $key
58 }
59 return $names
60 }
61
62 proc combine-results {results} {
63 set tests [get-test-names [lindex $results 1]]
64 foreach test $tests {
65 puts $test
66 foreach {branch output} $results {
67 puts [format "%-20s %s" \
68 $branch [get-result-with-name $output $test]]
69 }
70 puts {}
71 }
72 }
73
74 proc main {} {
75 # Note: the first branch is only used in order to get the redis-benchmark
76 # executable. Tests are performed starting from the second branch.
77 set branches {
78 slowset 2.2.0 2.4.0 unstable slowset
79 }
80 set results [run-tests $branches]
81 puts [combine-results $results]
82 }
83
84 # Force the user to run the script from the 'utils' directory.
85 if {![file exists speed-regression.tcl]} {
86 puts "Please make sure to run speed-regression.tcl while inside /utils."
87 puts "Example: cd utils; ./speed-regression.tcl"
88 exit 1
89 }
90 main