summaryrefslogtreecommitdiff
path: root/benchmark.py
blob: 02f4e4df30cd39108a581c968402fd41d9bbc996 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
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))