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
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.
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.
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.
Reddi et al. (2020). MLPerf Inference Benchmark. ISCANot 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
Assistant Professor of Artificial Intelligence and Deep Learning
University of Al-Qadisiyah
About
Researcher and academic specialising in artificial intelligence (AI), deep learning, computer vision and natural language processing (NLP). The “Deep Learning in Arabic” project aims to enrich Arabic scientific and technical content with sound, free references and software for researchers and learners across the Arab world.
Edge AI Assistant
I am the Edge AI Assistant. Ask about a concept, technology, board or project and I will answer from the lab content with links.
Edge AI Assistant
Local Database Mode
Answers from the lab knowledge base only, without sending your question to any external party. Conversations are not stored.
Smart assistant
Answers from the site’s content
The assistant can make mistakes, so check the attached sources.
Welcome! I am Dr. Alaa Taima, and this is my smart assistant on “Deep Learning in Arabic”. Ask it about any term or topic in artificial intelligence, and it will answer from the site's content with links to the sources.
DL Bot
Your smart assistant · Connecting…
Enter to send · Shift + Enter for a new line · The assistant can make mistakes, so check the sources.