diff options
author | Ben Connors <benconnors@outlook.com> | 2019-01-25 14:50:36 -0500 |
---|---|---|
committer | Ben Connors <benconnors@outlook.com> | 2019-01-25 14:50:36 -0500 |
commit | a9c15b92d5ec6e88bca57a75fb0cbd3cd6b3fd76 (patch) | |
tree | 51fa702bfb7c23f1ae72537529d9c2c5afc21a7a /benchmark.py | |
parent | 8d814c0bc5b7b9e34355cf8502579f501592e0a4 (diff) |
Add some utilities
Diffstat (limited to 'benchmark.py')
-rwxr-xr-x | benchmark.py | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/benchmark.py b/benchmark.py new file mode 100755 index 0000000..02f4e4d --- /dev/null +++ b/benchmark.py @@ -0,0 +1,91 @@ +#!/usr/bin/env python3 + +"""Basic benchmark for testing Show render performance. + +For each requested show, render_all() is benchmarked, render_all(minnx=MINNX) is tested, +is tested, a basic render() loop is tested, and a basic render() loop with minnx=MINNX is +tested. Note that no audio reading/decoding is done: that may slow things up. Ideally, pick a +MINNX value that gives you a lot of breathing room. +""" + +import sys +import time + +from blc.workspace import Workspace, SHOW + +MINNX = 10 + +if len(sys.argv) == 2: + sid = None + fname = sys.argv[1] +elif len(sys.argv) == 3: + sid = [int(i) for i in sys.argv[2].split(',')] + fname = sys.argv[1] +else: + print("Usage: %s <workspace> [show id]" % (sys.argv[0])) + sys.exit(1) + +w = Workspace.load(fname) + +if sid is None: + sid = [f.id for f in w.functions.values() if f.type == SHOW] + +render_all = [] +render_all_minnx = [] +render_loop = [] +render_loop_minnx = [] +render_worst = [] +render_worst_minnx = [] + +for s in map(lambda sid: w.functions[sid], sid): + print("Testing \"%s\"..." % s.name) + + print(" - render_all()") + start = time.monotonic() + s.render_all() + render_all.append(time.monotonic() - start) + print(" %2.4fs" % (render_all[-1])) + + print(" - render_all(minnx=%d)" % MINNX) + start = time.monotonic() + s.render_all(minnx=MINNX) + render_all_minnx.append(time.monotonic() - start) + print(" %2.4fs" % (render_all_minnx[-1])) + print(" %1.4fx faster" % (render_all[-1]/render_all_minnx[-1]-1)) + + print(" - render loop") + render_worst.append(0) + start = time.monotonic() + nx = 0 + t = 0 + data = None + while nx != -1: + onx = nx + sstart = time.monotonic() + _, _, nx, data = s.render(t, data=data) + if onx != 0: + render_worst[-1] = max(render_worst[-1], (1000*(time.monotonic() - sstart)/onx)) + t += nx + render_loop.append(time.monotonic() - start) + print(" %2.4fs" % (render_loop[-1])) + print(" %3.2f%% worst case" % (100*render_worst[-1])) + + print(" - render loop, minnx=%d" % MINNX) + render_worst_minnx.append(0) + start = time.monotonic() + nx = 0 + t = 0 + data = None + while nx != -1: + onx = nx + sstart = time.monotonic() + _, _, nx, data = s.render(t, data=data) + if onx != 0: + render_worst_minnx[-1] = max(render_worst_minnx[-1], (1000*(time.monotonic() - sstart)/onx)) + if nx != -1: + nx = max(nx, MINNX) + t += nx + render_loop_minnx.append(time.monotonic() - start) + print(" %2.4fs" % (render_loop_minnx[-1])) + print(" %3.2f%% worst case" % (100*render_worst_minnx[-1])) + print(" %1.4fx faster" % (render_loop[-1]/render_loop_minnx[-1] - 1)) |