diff --git a/contrib/revsetbenchmarks.sh b/contrib/revsetbenchmarks.py rename from contrib/revsetbenchmarks.sh rename to contrib/revsetbenchmarks.py --- a/contrib/revsetbenchmarks.sh +++ b/contrib/revsetbenchmarks.py @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/usr/bin/env python # Measure the performance of a list of revsets against multiple revisions # defined by parameter. Checkout one by one and run perfrevset with every @@ -13,77 +13,46 @@ # This script also does one run of the current version of mercurial installed # to compare performance. -HG="hg update" +import sys +from subprocess import check_call, check_output + +HG="hg update --quiet --check" PERF="./hg --config extensions.perf=contrib/perf.py perfrevset" -BASE_PERF="hg --config extensions.perf=contrib/perf.py perfrevset" -TARGETS=$1 -shift -# read from a file or from standard output -if [ $# -ne 0 ]; then - readarray REVSETS < $1 -else - readarray REVSETS -fi +target_rev = sys.argv[1] -hg update --quiet +revsetsfile = sys.stdin +if len(sys.argv) > 2: + revsetsfile = open(sys.argv[2]) -echo "Starting time benchmarking" -echo +revsets = [l.strip() for l in revsetsfile] -echo "Revsets to benchmark" -echo "----------------------------" +print "Revsets to benchmark" +print "----------------------------" -for (( j = 0; j < ${#REVSETS[@]}; j++ )); -do - echo "${j}) ${REVSETS[$j]}" -done - -echo "----------------------------" -echo +for idx, rset in enumerate(revsets): + print "%i) %s" % (idx, rset) -# Benchmark baseline -echo "Benchmarking baseline" +print "----------------------------" +print -for (( j = 0; j < ${#REVSETS[@]}; j++ )); - do - echo -n "${j}) " - $BASE_PERF "${REVSETS[$j]}" -done +revs = check_output("hg log --template='{rev}\n' --rev " + target_rev, + shell=True); -echo -echo +revs = [r for r in revs.split() if r] # Benchmark revisions -for i in $(hg log --template='{rev}\n' --rev $TARGETS); -do - echo "----------------------------" - echo -n "Revision: " - hg log -r $i --template "{desc|firstline}\n" - - echo "----------------------------" - $HG $i - for (( j = 0; j < ${#REVSETS[@]}; j++ )); - do - echo -n "${j}) " - $PERF "${REVSETS[$j]}" - done - echo "----------------------------" -done +for r in revs: + print "----------------------------" + sys.stdout.write("Revision: ") + sys.stdout.flush() + check_call('hg log -r %s --template "{desc|firstline}\n"' % r, shell=True) -$HG - -# Benchmark current code -echo "Benchmarking current code" + print "----------------------------" + check_call(HG + ' ' + r, shell=True) + for idx, rset in enumerate(revsets): + sys.stdout.write("%i) " % idx) + sys.stdout.flush() + check_call(PERF + ' "%s"' % rset, shell=True) + print "----------------------------" -for (( j = 0; j < ${#REVSETS[@]}; j++ )); - do - echo -n "${j}) " - $PERF "${REVSETS[$j]}" -done - - -echo -echo "Time benchmarking finished" - -