~exarkun/twisted-benchmarks/trunk

« back to all changes in this revision

Viewing changes to benchlib.py

  • Committer: Jean-Paul Calderone
  • Date: 2011-07-21 22:38:31 UTC
  • mfrom: (49.1.1 multiprocess)
  • Revision ID: exarkun@divmod.com-20110721223831-fp8fbjepxfu1fp61
Switch to a multiprocess runner approach to isolate benchmarks from each other more.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
 
2
2
from __future__ import division
3
3
 
4
 
import sys
 
4
import sys, subprocess
5
5
 
6
 
from twisted.python import log
 
6
from twisted.python import log, reflect
7
7
from twisted.internet.defer import Deferred
8
8
from twisted.internet.task import cooperate
9
9
from twisted.application.app import ReactorSelectionMixin
104
104
class Driver(object):
105
105
    benchmark_report = staticmethod(benchmark_report)
106
106
 
 
107
    def main(self):
 
108
        benchmark = reflect.namedAny(sys.argv[1])
 
109
        self.driver(benchmark, sys.argv[2:])
 
110
 
 
111
 
107
112
    def driver(self, f, argv):
108
113
        options = BenchmarkOptions()
109
114
        options.parseOptions(argv[1:])
119
124
        reactor.run()
120
125
 
121
126
 
122
 
    def multidriver(self, f):
123
 
        options = BenchmarkOptions()
124
 
        options.parseOptions(sys.argv[1:])
125
 
        self.run_jobs(
126
 
            f, options['duration'], options['iterations'], options['warmup'])
 
127
    def multidriver(self, benchmarks):
 
128
        for benchmark in benchmarks:
 
129
            child = subprocess.Popen([
 
130
                    sys.executable, '-c',
 
131
                    'import benchlib\n'
 
132
                    'benchlib.main()\n',
 
133
                    benchmark] + sys.argv[1:])
 
134
            child.wait()
127
135
 
128
136
 
129
137
    def run_jobs(self, f, duration, iterations, warmup):
151
159
_driver = Driver()
152
160
driver = _driver.driver
153
161
multidriver = _driver.multidriver
 
162
main = _driver.main
154
163
del _driver