Spaces:
Running
Running
File size: 780 Bytes
173f28e f56dbf3 173f28e | 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 | from __future__ import annotations
import statistics
import time
def evaluate_speed(
model,
sentences: list[str],
num_runs: int = 3,
batch_size: int = 64,
) -> dict[str, float]:
"""Measure encoding latency. Returns median time and throughput."""
model.encode(sentences, batch_size=batch_size, show_progress_bar=False)
times: list[float] = []
for _ in range(num_runs):
start = time.perf_counter()
model.encode(sentences, batch_size=batch_size, show_progress_bar=False)
elapsed = time.perf_counter() - start
times.append(elapsed)
median_time = statistics.median(times)
return {
"median_seconds": round(median_time, 4),
"sentences_per_second": round(len(sentences) / median_time, 1),
}
|