[PATCH 3 of 9] revsetbenchmark: simplify and convert the script to python
pierre-yves.david at ens-lyon.org
pierre-yves.david at ens-lyon.org
Wed Mar 26 21:49:04 CDT 2014
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at fb.com>
# Date 1395882210 25200
# Wed Mar 26 18:03:30 2014 -0700
# Node ID 9df1c226d1cd2aca826dbea8c3fcd80cb2f20d19
# Parent 266d1d1378b5d1742d64eb7df31817d5bbf55599
revsetbenchmark: simplify and convert the script to python
The script is now in python. That translation is very raw, more improvement to
comes:
The "current code" and "base" entry have been dropped. This is trivial to get
same result using a tagged revision or "." in the list of benchmarked revision.
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,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"
-
-
More information about the Mercurial-devel
mailing list