<commit_before>#!/usr/bin/env tclsh8.5
# Copyright (C) 2011 <NAME>
# Released under the BSD license like Redis itself

proc run-tests branches {
    set runs {}
    set branch_id 0
    foreach b $branches {
        cd ../src
        puts "Benchmarking $b"
        exec -ignorestderr git checkout $b 2> /dev/null
        exec -ignorestderr make clean 2> /dev/null
        puts "  compiling..."
        exec -ignorestderr make 2> /dev/null

        if {$branch_id == 0} {
            puts "  copy redis-benchmark from unstable to /tmp..."
            exec -ignorestderr cp ./redis-benchmark /tmp
            incr branch_id
            continue
        }

        # Start the Redis server
        puts "  starting the server... [exec ./redis-server -v]"
        set pids [exec echo "port 12123\nloglevel warning\n" | ./redis-server - > /dev/null 2> /dev/null &]
        after 1000
        puts "  running the benchmark"
        set output [exec /tmp/redis-benchmark -n 100000 --csv -p 12123]
        lappend runs $b $output
        puts "  killing server..."
        catch {
            exec kill -9 [lindex $pids 0]
            exec kill -9 [lindex $pids 1]
        }
        incr branch_id
    }
    return $runs
}

proc get-result-with-name {output name} {
    foreach line [split $output "\n"] {
        lassign [split $line ","] key value
        set key [string tolower [string range $key 1 end-1]]
        set value [string range $value 1 end-1]
        if {$key eq [string tolower $name]} {
            return $value
        }
    }
    return "n/a"
}

proc combine-results {results} {
    set tests {
        ping set get incr lpush lpop sadd spop
        "lrange (first 100 elements)"
        "lrange (first 600 elements)"
        "mset (10 keys)"
    }
    foreach test $tests {
        puts $test<commit_msg>speed-regression.tcl script: obtain test names dynamically.<commit_after>#!/usr/bin/env tclsh8.5
# Copyright (C) 2011 <NAME>
# Released under the BSD license like Redis itself

proc run-tests branches {
    set runs {}
    set branch_id 0
    foreach b $branches {
        cd ../src
        puts "Benchmarking $b"
        exec -ignorestderr git checkout $b 2> /dev/null
        exec -ignorestderr make clean 2> /dev/null
        puts "  compiling..."
        exec -ignorestderr make 2> /dev/null

        if {$branch_id == 0} {
            puts "  copy redis-benchmark from unstable to /tmp..."
            exec -ignorestderr cp ./redis-benchmark /tmp
            incr branch_id
            continue
        }

        # Start the Redis server
        puts "  starting the server... [exec ./redis-server -v]"
        set pids [exec echo "port 12123\nloglevel warning\n" | ./redis-server - > /dev/null 2> /dev/null &]
        after 1000
        puts "  running the benchmark"
        set output [exec /tmp/redis-benchmark -n 100000 --csv -p 12123]
        lappend runs $b $output
        puts "  killing server..."
        catch {
            exec kill -9 [lindex $pids 0]
            exec kill -9 [lindex $pids 1]
        }
        incr branch_id
    }
    return $runs
}

proc get-result-with-name {output name} {
    foreach line [split $output "\n"] {
        lassign [split $line ","] key value
        set key [string tolower [string range $key 1 end-1]]
        set value [string range $value 1 end-1]
        if {$key eq [string tolower $name]} {
            return $value
        }
    }
    return "n/a"
}

proc get-test-names output {
    set names {}
    foreach line [split $output "\n"] {
        lassign [split $line ","] key value
        set key [string tolower [string range $key 1 end-1]]
        lappend names $key
    }
    return $names
}

proc combine-results {results} {
    set tests [get-test-names [lindex $results 1]]
    foreach test $tests {
        puts $test
{'fraction_non_alphanumeric': 0.10588544403573305, 'fraction_numerical': 0.023909616395165527, 'mean_word_length': 1.7747813411078717, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3071855', 'n_tokens_mistral': 1239, 'n_tokens_neox': 1170, 'n_words': 414}