Comments
Patch
rename from contrib/revsetbenchmarks.sh
rename to contrib/revsetbenchmarks.py
@@ -1,6 +1,6 @@
-#!/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
# revset in the list to benchmark its performance.
#
@@ -11,79 +11,48 @@
# You should run this from the root of your mercurial repository.
#
# 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
+for idx, rset in enumerate(revsets):
+ print "%i) %s" % (idx, rset)
-echo "----------------------------"
-echo
+print "----------------------------"
+print
-# Benchmark baseline
-echo "Benchmarking baseline"
+revs = check_output("hg log --template='{rev}\n' --rev " + target_rev,
+ shell=True);
-for (( j = 0; j < ${#REVSETS[@]}; j++ ));
- do
- echo -n "${j}) "
- $BASE_PERF "${REVSETS[$j]}"
-done
-
-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"
+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)
- echo "----------------------------"
- $HG $i
- for (( j = 0; j < ${#REVSETS[@]}; j++ ));
- do
- echo -n "${j}) "
- $PERF "${REVSETS[$j]}"
- done
- echo "----------------------------"
-done
+ 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 "----------------------------"
-$HG
-
-# Benchmark current code
-echo "Benchmarking current code"
-
-for (( j = 0; j < ${#REVSETS[@]}; j++ ));
- do
- echo -n "${j}) "
- $PERF "${REVSETS[$j]}"
-done
-
-
-echo
-echo "Time benchmarking finished"
-
-