File size: 2,186 Bytes
5dd27d0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Time the browser-free engine: per-frame simulate + export + pipe, at the live 24 fps cadence."""
import json
import statistics
import time

from engine_client import Engine

started = time.perf_counter()
engine = Engine()
boot_ms = (time.perf_counter() - started) * 1e3
scene = engine.scene
print(json.dumps(dict(boot_ms=round(boot_ms), draws=len(scene['draws']), geometries=len(scene['geometries']),
    materials=sorted({m['type'] for m in scene['materials']}), lights=scene['lights'],
    triangles=int(sum(g['indices'] for g in scene['geometries']) // 3), clear=scene['clearColor'],
    tone=scene['toneMapping'], exposure=scene['exposure'])))

rows = []
for i in range(480):
    target = round((i + 1) * 60 / 24)
    events = [{'action': 'enter', 'phase': 'down'}, {'action': 'enter', 'phase': 'up'}] if i == 5 else []
    if 40 <= i < 400 and i % 20 == 0:
        events.append({'action': 'w', 'phase': 'down' if (i // 20) % 2 == 0 else 'up'})
    if 60 <= i < 400 and i % 37 == 0:
        events += [{'action': 'j', 'phase': 'down'}, {'action': 'j', 'phase': 'up'}]
    capture = (i % 4) == 0  # one condition frame per latent frame
    t0 = time.perf_counter()
    header, arrays = engine.advance(target, events, capture=capture)
    rows.append(dict(capture=capture, total=(time.perf_counter() - t0) * 1e3, **header['timing'],
                     bytes=sum(a.nbytes for a in arrays.values())))
state = header.get('state') or {}
engine.close()

def stat(xs):
    xs = sorted(xs)
    return dict(n=len(xs), median=round(xs[len(xs) // 2], 3), p95=round(xs[int(len(xs) * .95)], 3), max=round(xs[-1], 3))
steady = rows[30:]
print(json.dumps(dict(
    sim_only_frame_ms=stat([r['total'] for r in steady if not r['capture']]),
    capture_frame_ms=stat([r['total'] for r in steady if r['capture']]),
    node_simulate_ms=stat([r['simulate_ms'] for r in steady]),
    node_export_ms=stat([r['export_ms'] for r in steady if r['capture']]),
    capture_bytes=steady[0]['bytes'] if steady[0]['capture'] else max(r['bytes'] for r in steady),
    final_state={k: state.get(k) for k in ('state', 'elapsed', 'shots', 'hits', 'kills', 'health', 'ammo')},
    player=state.get('player'))))