blinklinmult.bench.systems

The environment a measurement was taken in, and the resources it used.

A latency figure without its machine is not a measurement, so every benchmark result carries a MachineSpec: hardware, library versions, thread settings and the commit that produced it. Without those a reader cannot tell whether a number disagrees with theirs because the code changed or because the laptop did.

Attributes

CONTENTION_FRACTION

Share of the cores that, once busy, makes a timing untrustworthy.

RSS_DIVISOR

Divisor turning ru_maxrss into megabytes.

Classes

MachineSpec

Where and with what a measurement was taken.

Functions

peak_rss_mb(→ float)

Peak resident memory this process has reached, in megabytes.

artifact_size_bytes(→ int)

Size of a weights file on disk.

pin_threads(→ None)

Pin every framework's thread pool to one count.

Module Contents

blinklinmult.bench.systems.CONTENTION_FRACTION = 0.5

Share of the cores that, once busy, makes a timing untrustworthy.

Half rather than all: measured on this machine, a one-minute load of 7.0 against 10 cores inflated every model’s latency by ~1.7x. A threshold at saturation would have called that idle.

blinklinmult.bench.systems.RSS_DIVISOR = 1024

Divisor turning ru_maxrss into megabytes.

The units differ by platform and nothing warns about it: macOS reports bytes, Linux reports kibibytes. Hard-coding either gives numbers 1024x wrong on the other, in a field a reader has no way to sanity-check.

class blinklinmult.bench.systems.MachineSpec[source]

Where and with what a measurement was taken.

Parameters:
  • platform (str) – OS and architecture.

  • processor (str) – CPU, where the platform reports one.

  • cpu_count (int) – Logical cores visible.

  • python (str) – Interpreter version.

  • torch (str) – Torch version, or empty when absent.

  • onnxruntime (str) – onnxruntime version, or empty when absent.

  • numpy (str) – numpy version.

  • threads (int) – Threads the run was pinned to.

  • git_sha (str) – Commit the code was at.

  • load_average (tuple[float, float, float]) – System load at capture, so a run taken on a busy machine can be recognised as such rather than quietly reported as the model being slow.

classmethod capture(threads: int) → MachineSpec[source]

Record the current environment.

Parameters:

threads (int) – Threads the benchmark was pinned to.

Returns:

The environment block.

Return type:

MachineSpec

property contended: bool

Whether the machine looked busy enough to distort timings.

The bar is CONTENTION_FRACTION of the core count, not full saturation. Measured here: at load 7.0 on 10 cores – comfortably below saturation – the same models timed 1.7x slower than on an idle machine. Waiting for load to exceed the core count would let that pass unremarked, and a benchmark that silently reports contention as model latency is worse than no benchmark.

Returns:

Whether one-minute load crossed the fraction.

Return type:

bool

describe() → str[source]

One line naming the machine.

Returns:

Platform, cores, thread pinning.

Return type:

str

blinklinmult.bench.systems.peak_rss_mb() → float[source]

Peak resident memory this process has reached, in megabytes.

A high-water mark, not a current reading, so it never misses a transient spike between samples – and never falls, which is why callers take a difference around the region they care about.

Returns:

Megabytes.

Return type:

float

blinklinmult.bench.systems.artifact_size_bytes(path: pathlib.Path | str) → int[source]

Size of a weights file on disk.

Parameters:

path (Path | str) – The artifact.

Returns:

Bytes.

Return type:

int

Raises:

FileNotFoundError – If the file is absent, rather than reporting zero and letting a missing artifact look like a very small one.

blinklinmult.bench.systems.pin_threads(threads: int) → None[source]

Pin every framework’s thread pool to one count.

Sets the environment variables and the runtime knobs. The environment ones only take effect before the libraries load, so this is best called early; setting both means a late call still pins torch, which is the one that measurably moves.

Parameters:

threads (int) – Threads to allow.

Raises:

ValueError – If threads is not positive.