Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Support for benchmarking within a git repo.

  • Loading branch information...
commit 5510f26f90ac3ee23674a11c07f172ae0806a3dd 1 parent 9b1869d
@jacobian jacobian authored
Showing with 46 additions and 17 deletions.
  1. +9 −1 README.rst
  2. +37 −16 djangobench/main.py
View
10 README.rst
@@ -10,7 +10,7 @@ Running the benchmarks
Here's the short version::
mkvirtualenv --no-site-packages djangobench
- pip install djangobench
+ pip install -e git://github.com/jacobian/djangobench.git#egg=djangobench
svn co http://code.djangoproject.com/svn/django/tags/releases/1.2/ django-control
svn co http://code.djangoproject.com/svn/django/trunk django-experiment
djangobench
@@ -32,6 +32,14 @@ them: ``djangobench`` works its magic by mucking with ``PYTHONPATH``.
However, the benchmarks themselves need access to the ``djangobench``
module, so you'll need to install it.
+If you're feeling fancy, you can use one of them there newfangled DVCSes instead
+and test against a single repository containing branches::
+
+ git clone git@github.com:django/django.git
+ djangobench --vcs=git --control=1.2 --experiment=trunk
+
+Git's the only supported VCS right now, but patches are welcome.
+
At the time of this writing Django's trunk hasn't significantly diverged
from Django 1.2, so you should expect to see not-statistically-significant
results::
View
53 djangobench/main.py
@@ -4,6 +4,7 @@
Run us some Django benchmarks.
"""
+import subprocess
import argparse
import email
import simplejson
@@ -15,7 +16,7 @@
DEFAULT_BENCMARK_DIR = Path(__file__).parent.child('benchmarks').absolute()
-def run_benchmarks(control, experiment, benchmark_dir, benchmarks, trials, record_dir=None):
+def run_benchmarks(control, experiment, benchmark_dir, benchmarks, trials, vcs=None, record_dir=None):
if benchmarks:
print "Running benchmarks: %s" % " ".join(benchmarks)
else:
@@ -26,23 +27,23 @@ def run_benchmarks(control, experiment, benchmark_dir, benchmarks, trials, recor
if not record_dir.exists():
raise ValueError('Recording directory "%s" does not exist' % record_dir)
print "Recording data to '%s'" % record_dir
-
- control_label = get_django_version(control)
- experiment_label = get_django_version(experiment)
- print "Control: Django %s (in %s)" % (control_label, control)
- print "Experiment: Django %s (in %s)" % (experiment_label, experiment)
+
+ control_label = get_django_version(control, vcs=vcs)
+ experiment_label = get_django_version(experiment, vcs=vcs)
+ branch_info = "%s branch " % vcs if vcs else ""
+ print "Control: Django %s (in %s%s)" % (control_label, branch_info, control)
+ print "Experiment: Django %s (in %s%s)" % (experiment_label, branch_info, experiment)
print
# Calculate the subshell envs that we'll use to execute the
# benchmarks in.
- control_env = {'PYTHONPATH': ':'.join([
- Path(control).absolute(),
- Path(benchmark_dir),
- ])}
- experiment_env = {'PYTHONPATH': ':'.join([
- Path(experiment).absolute(),
- Path(benchmark_dir),
- ])}
+ if vcs:
+ control_env = experiment_env = {
+ 'PYTHONPATH': '%s:%s' % (Path.cwd().absolute(), Path(benchmark_dir)),
+ }
+ else:
+ control_env = {'PYTHONPATH': '%s:%s' % (Path(control).absolute(), Path(benchmark_dir))}
+ experiment_env = {'PYTHONPATH': '%s:%s' % (Path(experiment).absolute(), Path(benchmark_dir))}
for benchmark in discover_benchmarks(benchmark_dir):
if not benchmarks or benchmark.name in benchmarks:
@@ -52,7 +53,9 @@ def run_benchmarks(control, experiment, benchmark_dir, benchmarks, trials, recor
experiment_env['DJANGO_SETTINGS_MODULE'] = settings_mod
try:
+ if vcs: switch_to_branch(vcs, control)
control_data = run_benchmark(benchmark, trials, control_env)
+ if vcs: switch_to_branch(vcs, experiment)
experiment_data = run_benchmark(benchmark, trials, experiment_env)
except SkipBenchmark, reason:
print "Skipped: %s\n" % reason
@@ -204,13 +207,25 @@ def format_benchmark_result(result, num_points):
else:
return str(result)
-def get_django_version(djangodir):
+def get_django_version(loc, vcs=None):
+ if vcs:
+ switch_to_branch(vcs, loc)
+ pythonpath = Path.cwd()
+ else:
+ pythonpath = Path(loc).absolute()
out, err, _ = perf.CallAndCaptureOutput(
[sys.executable, '-c' 'import django; print django.get_version()'],
- env = {'PYTHONPATH': Path(djangodir).absolute()}
+ env = {'PYTHONPATH': pythonpath}
)
return out.strip()
+def switch_to_branch(vcs, branchname):
+ if vcs == 'git':
+ cmd = ['git', 'checkout', branchname]
+ else:
+ raise ValueError("Sorry, %s isn't supported (yet?)" % vcs)
+ subprocess.check_call(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+
def main():
parser = argparse.ArgumentParser()
parser.add_argument(
@@ -226,6 +241,11 @@ def main():
help = "Path to the Django version to use as experiment."
)
parser.add_argument(
+ '--vcs',
+ choices = ['git'],
+ help = 'Use a VCS for control/experiment. Makes --control/--experiment specify branches, not paths.'
+ )
+ parser.add_argument(
'-t', '--trials',
type = int,
default = 50,
@@ -260,6 +280,7 @@ def main():
benchmark_dir = args.benchmark_dir,
benchmarks = args.benchmarks,
trials = args.trials,
+ vcs = args.vcs,
record_dir = args.record,
)
Please sign in to comment.
Something went wrong with that request. Please try again.