1. Team SimPy
  2. Untitled project
  3. simpy-benchmarks

Commits

Stefan Scherfke  committed ea66e53

Initial import for the SimPy benchmarking utils.

  • Participants
  • Branches default

Comments (0)

Files changed (6)

File .hgignore

View file
+syntax: glob
+
+*.pyc
+
+.DS_Store

File benchmark.py

View file
+# Run SimPy benchmarks.
+#
+# Usage:
+#
+# python benchmark.py
+#     Run selected benchmarks for the tip revision.
+#
+# python benchmark.py 2vs3
+#     Run selected benchmarks for SimPy 2.3 and the tip revision.
+#
+# python benchmark.py [REV+]
+#     Run selected benchmarks for all specified revisions.
+#
+#
+# Config:
+repo = '/Users/stefan/Code/simpy'
+benchmarks = [
+    ('simple_sim', '1000, 1000'),
+    ('simple_sim', '10, 100000'),
+    ('simple_sim', '100000, 10'),
+]
+num_runs = 1
+profile = False
+
+# Don't change anything from here.
+import cProfile
+import subprocess
+import sys
+import timeit
+
+
+def run_benchmark(simpy, rev, module, args):
+    """Run one benchmark module and print its results."""
+    print('Running %s[%s].%s(%s) ...' % (simpy, rev, module, args))
+    subprocess.call('hg up %s -R %s' % (rev, repo), stdout=subprocess.PIPE,
+                    shell=True)
+    res = timeit.repeat('benchmark(%s)' % args,
+                        'from %s.%s import benchmark' % (simpy, module),
+                        repeat=num_runs, number=1)
+    print('... %.2fs' % min(res))
+
+    if profile:
+        cProfile.run('from %s.%s import benchmark; benchmark(%s)' %
+                                                     (simpy, module, args))
+
+
+def run_benchmarks(simpy, rev):
+    """Run all benchmarks for revision ``rev.``."""
+    sys.path.insert(0, repo)
+    print('Running benchmarks for Rev. %s ...' % rev)
+    for module, args in benchmarks:
+        run_benchmark(simpy, rev, module, args)
+
+
+def main():
+    print('Best of %s runs:' % num_runs)
+    if len(sys.argv) == 1:
+        run_benchmarks('simpy3', 'tip')
+
+    elif sys.argv[1] == '2vs3':
+        run_benchmarks('simpy2', '2.3.1')
+        run_benchmarks('simpy3', 'tip')
+
+    else:
+        for rev in sys.argv[1:]:
+            run_benchmarks('simpy3', rev)
+
+
+if __name__ == '__main__':
+    main()

File simpy2/__init__.py

Empty file added.

File simpy2/simple_sim.py

View file
+from SimPy.Simulation import Simulation, Process, hold
+
+
+class Proc(Process):
+    def pem(self):
+        while True:
+            yield hold, self, 1
+
+
+def benchmark(procs=100, until=100):
+    sim = Simulation()
+    for i in range(procs):
+        p = Proc(sim=sim)
+        sim.activate(p, p.pem())
+    sim.simulate(until=until)

File simpy3/__init__.py

Empty file added.

File simpy3/simple_sim.py

View file
+from simpy import Environment, simulate
+
+
+def pem(env):
+    while True:
+        yield env.hold(1)
+
+
+def benchmark(procs=100, until=100):
+    env = Environment()
+    for i in range(procs):
+        env.start(pem(env))
+    simulate(env, until)