diff options
-rwxr-xr-x | benchmark.py | 91 | ||||
-rwxr-xr-x | tktest.py | 43 |
2 files changed, 134 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)) diff --git a/tktest.py b/tktest.py new file mode 100755 index 0000000..d8f759c --- /dev/null +++ b/tktest.py @@ -0,0 +1,43 @@ +#!/usr/bin/env python3 + +"""Basic testing for Show rendering with Tk output.""" + +import threading +import time +from tkinter import Tk, N, E, S, W, Label +import sys + +from blc.workspace import Workspace +from blc.tk import TkOutput +from blc.render import BasicRenderer + +def update_time(m, l, r): + l.config(text="%.1f" % ((time.monotonic() - r.start_time) if r.start_time is not None else 0)) + m.after(50, lambda: update_time(m,l,r)) + +if len(sys.argv) != 3: + print("Usage: %s <workspace> <show id>" % sys.argv[0]) + sys.exit(1) + +w = Workspace.load(sys.argv[1]) +s = w.functions[int(sys.argv[2])] + +root = Tk() +root.columnconfigure(0, weight=1) +root.rowconfigure(0, weight=1) + +output = TkOutput(root) +output.grid(row=0, sticky=N+E+S+W) + +label = Label(root) +label.grid(row=1,sticky=N+E+S+W) + +root.wm_title("BLC+ TkTest - "+s.name) + +renderer = BasicRenderer(s, output, minnx=13) +rthread = threading.Thread(target=renderer.start) +rthread.start() + +root.after(50, lambda: update_time(root, label, renderer)) + +root.mainloop() |