blc - Simple program for rendering QLC+ workspaces properly/without crashing. Developed into BLC2.

git clone https://benconnors.ca/git-repos/blc

About | Log | Files | Refs

benchmark.py (2747B) - raw


      1 #!/usr/bin/env python3
      2 
      3 """Basic benchmark for testing Show render performance.
      4 
      5 For each requested show, render_all() is benchmarked, render_all(minnx=MINNX) is tested, 
      6 is tested, a basic render() loop is tested, and a basic render() loop with minnx=MINNX is 
      7 tested. Note that no audio reading/decoding is done: that may slow things up. Ideally, pick a 
      8 MINNX value that gives you a lot of breathing room.
      9 """
     10 
     11 import sys
     12 import time
     13 
     14 from blc.workspace import Workspace, SHOW
     15 
     16 MINNX = 10
     17 
     18 if len(sys.argv) == 2:
     19     sid = None
     20     fname = sys.argv[1]
     21 elif len(sys.argv) == 3:
     22     sid = [int(i) for i in sys.argv[2].split(',')]
     23     fname = sys.argv[1]
     24 else:
     25     print("Usage: %s <workspace> [show id]" % (sys.argv[0]))
     26     sys.exit(1)
     27 
     28 w = Workspace.load(fname)
     29 
     30 if sid is None:
     31     sid = [f.id for f in w.functions.values() if f.type == SHOW]
     32 
     33 render_all = []
     34 render_all_minnx = []
     35 render_loop = []
     36 render_loop_minnx = []
     37 render_worst = []
     38 render_worst_minnx = []
     39 
     40 for s in map(lambda sid: w.functions[sid], sid):
     41     print("Testing \"%s\"..." % s.name)
     42 
     43     print("  - render_all()")
     44     start = time.monotonic()
     45     s.render_all()
     46     render_all.append(time.monotonic() - start)
     47     print("    %2.4fs" % (render_all[-1]))
     48 
     49     print("  - render_all(minnx=%d)" % MINNX)
     50     start = time.monotonic()
     51     s.render_all(minnx=MINNX)
     52     render_all_minnx.append(time.monotonic() - start)
     53     print("    %2.4fs" % (render_all_minnx[-1]))
     54     print("    %1.4fx faster" % (render_all[-1]/render_all_minnx[-1]-1)) 
     55 
     56     print("  - render loop")
     57     render_worst.append(0)
     58     start = time.monotonic()
     59     nx = 0
     60     t = 0
     61     data = None
     62     while nx != -1:
     63         onx = nx
     64         sstart = time.monotonic()
     65         _, _, nx, data = s.render(t, data=data)
     66         if onx != 0:
     67             render_worst[-1] = max(render_worst[-1], (1000*(time.monotonic() - sstart)/onx))
     68         t += nx
     69     render_loop.append(time.monotonic() - start)
     70     print("    %2.4fs" % (render_loop[-1]))
     71     print("    %3.2f%% worst case" % (100*render_worst[-1]))
     72 
     73     print("  - render loop, minnx=%d" % MINNX)
     74     render_worst_minnx.append(0)
     75     start = time.monotonic()
     76     nx = 0
     77     t = 0
     78     data = None
     79     while nx != -1:
     80         onx = nx
     81         sstart = time.monotonic()
     82         _, _, nx, data = s.render(t, data=data)
     83         if onx != 0:
     84             render_worst_minnx[-1] = max(render_worst_minnx[-1], (1000*(time.monotonic() - sstart)/onx))
     85         if nx != -1:
     86             nx = max(nx, MINNX)
     87         t += nx
     88     render_loop_minnx.append(time.monotonic() - start)
     89     print("    %2.4fs" % (render_loop_minnx[-1]))
     90     print("    %3.2f%% worst case" % (100*render_worst_minnx[-1]))
     91     print("    %1.4fx faster" % (render_loop[-1]/render_loop_minnx[-1] - 1))