File size: 1,020 Bytes
2a762ba
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Benchmark latency and memory usage."""

import time
import tracemalloc

import numpy as np

from app.core.pipeline import AnalysisPipeline


def benchmark(duration_seconds: float = 10.0):
    sr = 16000
    t = np.linspace(0, duration_seconds, int(sr * duration_seconds))
    audio = 0.3 * np.sin(2 * np.pi * 440 * t).astype(np.float32)

    pipeline = AnalysisPipeline()

    # Warmup
    pipeline.process_audio(audio[: sr * 3], sr)

    # Benchmark
    tracemalloc.start()
    start = time.time()
    result = pipeline.process_audio(audio, sr)
    elapsed = time.time() - start
    current, peak = tracemalloc.get_traced_memory()
    tracemalloc.stop()

    print(f"Duration: {duration_seconds:.1f}s")
    print(f"Elapsed: {elapsed:.2f}s ({elapsed / duration_seconds:.2f}x RT)")
    print(f"Peak memory: {peak / 1024 / 1024:.1f} MB")
    print(f"Success: {result['success']}")
    if result["success"]:
        print(f"Overall score: {result['overall_score']:.1f}")


if __name__ == "__main__":
    benchmark(10.0)