]> git.saurik.com Git - redis.git/blob - utils/speed-regression.tcl
redis-benchmark: ability to run selected tests. Better help with examples.
[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 combine-results {results} {
53 set tests {
54 ping set get incr lpush lpop sadd spop
55 "lrange (first 100 elements)"
56 "lrange (first 600 elements)"
57 "mset (10 keys)"
58 }
59 foreach test $tests {
60 puts $test
61 foreach {branch output} $results {
62 puts [format "%-20s %s" \
63 $branch [get-result-with-name $output $test]]
64 }
65 puts {}
66 }
67 }
68
69 proc main {} {
70 # Note: the first branch is only used in order to get the redis-benchmark
71 # executable. Tests are performed starting from the second branch.
72 set branches {
73 slowset 2.2.0 2.4.0 unstable slowset
74 }
75 set results [run-tests $branches]
76 puts [combine-results $results]
77 }
78
79 # Force the user to run the script from the 'utils' directory.
80 if {![file exists speed-regression.tcl]} {
81 puts "Please make sure to run speed-regression.tcl while inside /utils."
82 puts "Example: cd utils; ./speed-regression.tcl"
83 exit 1
84 }
85 main