Inference benchmark
How long one prediction actually takes in your browser. The model is read out of demo.html at load, so this measures the same weights the demo predicts with and cannot drift from them. Numbers below are produced on your machine, right now.
Method
The clock is blunt
performance.now() is deliberately coarsened against timing attacks, typically to
100 µs unless the page is cross-origin isolated. One prediction is roughly a thousand times
shorter than that, so timing it alone reports 0 or one whole tick and nothing between. This page
measures the real resolution first, then sizes each batch to clear it by 200×.
The JIT deletes dead work
A prediction whose result is never read is work the optimiser is free to remove, and a loop whose inputs never change can be computed once and hoisted out. Every prediction here is summed into a running total that gets printed, and the square footage changes on every iteration.
The loop is not free
Iterating and mutating the input costs something too, and charging it to the model would overstate the result. The same loop runs a second time without the prediction, and both figures are reported, so the cost of the model alone is the difference.
The machine does not hold still
Press Run again a dozen times and watch the figure climb. On the laptop this was written on it went from 244 ns on the first pass to 321 ns by the twelfth, same code and same page, because the benchmark is heating the core it is timing. Leave it idle half a minute and it drops back. Any single run is a snapshot of one clock speed, which is why the site quotes a range rather than a figure.
Results
| operation | min | mean | p50 | p99 | batches |
|---|---|---|---|---|---|
| predict() | — | ||||
Loading the model from demo.html…
Environment
Reading it: predict() is the figure that matters, and it is the
line the site quotes. It is one evaluation of the model: six multiplies and six adds over weights
already in raw units, so no scaling happens at prediction time. It is not the cost of the
demo updating on screen, which is dominated by writing text into the DOM and is roughly a thousand
times larger. See the source
and write-up.