af8dd31debe607ccc9f83cf137ac6d9f4915d2c0
[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 source ../tests/support/redis.tcl
6 set ::port 12123
7
8 proc run-tests branches {
9 set runs {}
10 set branch_id 0
11 foreach b $branches {
12 cd ../src
13 puts "Benchmarking $b"
14 exec -ignorestderr git checkout $b 2> /dev/null
15 exec -ignorestderr make clean 2> /dev/null
16 puts " compiling..."
17 exec -ignorestderr make 2> /dev/null
18
19 if {$branch_id == 0} {
20 puts " copy redis-benchmark from unstable to /tmp..."
21 exec -ignorestderr cp ./redis-benchmark /tmp
22 incr branch_id
23 continue
24 }
25
26 # Start the Redis server
27 puts " starting the server... [exec ./redis-server -v]"
28 set pids [exec echo "port $::port\nloglevel warning\n" | ./redis-server - > /dev/null 2> /dev/null &]
29 puts " pids: $pids"
30 after 1000
31 puts " running the benchmark"
32
33 set r [redis 127.0.0.1 $::port]
34 set i [$r info]
35 puts " redis INFO shows version: [lindex [split $i] 0]"
36 $r close
37
38 set output [exec /tmp/redis-benchmark -n 100000 --csv -p $::port]
39 lappend runs $b $output
40 puts " killing server..."
41 catch {exec kill -9 [lindex $pids 0]}
42 catch {exec kill -9 [lindex $pids 1]}
43 incr branch_id
44 }
45 return $runs
46 }
47
48 proc get-result-with-name {output name} {
49 foreach line [split $output "\n"] {
50 lassign [split $line ","] key value
51 set key [string tolower [string range $key 1 end-1]]
52 set value [string range $value 1 end-1]
53 if {$key eq [string tolower $name]} {
54 return $value
55 }
56 }
57 return "n/a"
58 }
59
60 proc get-test-names output {
61 set names {}
62 foreach line [split $output "\n"] {
63 lassign [split $line ","] key value
64 set key [string tolower [string range $key 1 end-1]]
65 lappend names $key
66 }
67 return $names
68 }
69
70 proc combine-results {results} {
71 set tests [get-test-names [lindex $results 1]]
72 foreach test $tests {
73 puts $test
74 foreach {branch output} $results {
75 puts [format "%-20s %s" \
76 $branch [get-result-with-name $output $test]]
77 }
78 puts {}
79 }
80 }
81
82 proc main {} {
83 # Note: the first branch is only used in order to get the redis-benchmark
84 # executable. Tests are performed starting from the second branch.
85 set branches {
86 slowset 2.2.0 2.4.0 unstable slowset
87 }
88 set results [run-tests $branches]
89 puts [combine-results $results]
90 }
91
92 # Force the user to run the script from the 'utils' directory.
93 if {![file exists speed-regression.tcl]} {
94 puts "Please make sure to run speed-regression.tcl while inside /utils."
95 puts "Example: cd utils; ./speed-regression.tcl"
96 exit 1
97 }
98
99 # Make sure there is not already a server runnign on port 12123
100 set is_not_running [catch {set r [redis 127.0.0.1 $::port]}]
101 if {!$is_not_running} {
102 puts "Sorry, you have a running server on port $::port"
103 exit 1
104 }
105
106 main