Benchmarking on the edge

How to measure latency, throughput and memory correctly: warm-up, repetition, percentiles and honest reporting.

Intermediate10 min read

Educational draft content that needs expert review before it is used as an academic reference. Specifications, versions and licences change; check the official source. No experimental result is shown here unless it was actually run.

Learning objectives

  • Apply a correct measurement procedure
  • Distinguish latency from throughput
  • Report results with the measurement environment

Correct measurement needs a procedure: warm up, since the first inferences are slower while the runtime prepares memory and compiles. Then repeat tens or hundreds of times and report the median and percentiles (p90/p95), not the mean alone, since the slow tail matters for interactive apps.

Separate latency (one inference) from throughput (inferences per second). Measure pre- and post-processing apart from the model. In a browser the results depend on the browser, device, power state and number of tabs, so the numbers from your machine do not apply to others.

When publishing, record the environment (device, browser, version, threads) and state that the figures are local measurements, not specifications.

Terminology (with Arabic equivalents)

Warm-upالإحماء
Medianالوسيط
Percentile (p95)النسبة المئوية
Throughputالإنتاجية
Tail latencyكمون الذيل

Worked example

The classification and detection experiments in the lab show the inference time your browser measured for your run. Run them several times: the first is slower (warm-up) and the rest are closer to the stable value.

Code snippet

PythonMeasuring latency
import time, statistics

def bench(fn, warmup=5, runs=50):
    for _ in range(warmup):
        fn()
    ts = []
    for _ in range(runs):
        t = time.perf_counter(); fn(); ts.append((time.perf_counter() - t) * 1000)
    ts.sort()
    return {'median_ms': statistics.median(ts), 'p95_ms': ts[int(0.95 * len(ts)) - 1]}

An illustrative snippet that was not executed in the lab environment; check library versions in their official documentation before use.

Check yourself

  1. Why do we warm up the model before measuring?

    • The first inferences are slower
    • To reduce accuracy
    • To change the weights
    • No need
    Answer and explanation

    The first inferences are slower — Initialisation and compilation make the first ones slower.

  2. Why do we report percentiles?

    • To show the slow tail that affects the experience
    • To hide errors
    • To shorten the report
    • Because they are smaller
    Answer and explanation

    To show the slow tail that affects the experience — The mean hides rare slow values.

  3. The performance figures measured in your browser are:

    • Official specifications of the model
    • Local measurements that depend on your device
    • Constant on every device
    • Equal to cloud figures
    Answer and explanation

    Local measurements that depend on your device — They are affected by the device, the browser and the power state.

References

Suggested reading (links not verified yet)

  • Reddi et al. (2020). MLPerf Inference Benchmark. ISCA Not verified

Image and audio processing in the experiments runs inside your browser. Your images and audio are never uploaded and conversations are not stored. Privacy