Hands-on uuid.uuid4 vs uuid.uuid1 ID generation lab: real ops/s plus version/node checks, measured on Linux localhost today in this hands-on lab for SREs.
3 min read
Generate IDs with uuid.uuid4 (random) vs uuid.uuid1 (time + node). This lab reports ops/s on Linux localhost, plus version/node checks.
Related links:
Lab honesty (1 Oct 2026 IST): Python 3.13.5. Affiliates: 0. Differentiates from uuid4-vs-secrets (lab 41) — that post compared uuid4 to secrets tokens; this one is uuid4 vs uuid1.
Verdict up front (n=100000): uuid4 ~966847 ops/s; uuid1 ~217847; with str(): uuid4 ~598452 vs uuid1 ~193085.
| Arm | Pattern |
|---|---|
uuid.uuid4() | random v4 |
uuid.uuid1() | time/node v1 |
str(uuid.*) | hyphenated string |
.hex | 32-char hex |
Seven rounds, p50. Sample versions: v4=4, v1=1, uuid1 node present=True.
Script: lab-evidence/138-uuid4-vs-uuid1/results/run_lab.py.
| Arm | ops/s |
|---|---|
| uuid4 | 966847 |
| uuid4.hex | 758980 |
| uuid4 str | 598452 |
| uuid1 | 217847 |
| uuid1.hex | 215276 |
| uuid1 str | 193085 |
uuid4 led by about 4.4× on object generation.
Sample uuid1: f0ae2ffa-bd3a-11f1-b102-822b383dbcd0. Sample uuid4: 5a0e02bf-cad4-45ee-bdc2-acda319eb37c.
secrets).str only if you emit often.str(uuid4) fell to ~598452 ops/s from ~966847 object-only. Same pattern for uuid1 (~193085). Prefer .hex when you want compact text without hyphens (~758980).
If logs must not reveal which physical host minted an ID, skip uuid1 — its node field was non-zero on this box (node=True). If you only need “roughly increasing” IDs for debugging, uuid1’s timestamp can help operators skim timelines, but a server-side monotonic ID is usually clearer. Measure your generator under load before blaming the database for insert latency.
Lab 41 compared uuid4 to secrets token helpers. This post’s peer is uuid1. If you need opaque URL-safe tokens rather than UUID layout, prefer the secrets lab’s guidance; if you need UUID-shaped IDs, uuid4 ~966847 ops/s is the faster stdlib UUID here versus uuid1’s ~217847.
Evidence: summary.json, summary.txt.
One Linux box. Generation only — not collision tests, not DB index locality studies.
Store the UUID form your APIs already emit — converting layouts in every handler wastes the generator win.
uuid4 ~966847 ops/s beat uuid1 ~217847 and avoids time/node leakage. Prefer uuid4 for general IDs; use uuid1 only when you explicitly want its time+node properties.
Lab evidence
Lab 1 Oct 2026 IST. Python 3.13.5 on Linux localhost. n=100000, seven rounds, p50: uuid4 966847 ops/s; uuid1 217847. Checked version 4 vs 1 and uuid1 node present=True. Not lab 41 secrets. Affiliates: 0. Evidence: lab-evidence/138-uuid4-vs-uuid1/.
Hands-on platform.platform vs os.uname host inventory lab: real ops/s plus cache notes, measured on Linux localhost today in this hands-on lab for SREs.
Summary1 Oct 20264 min read
Hands-on cmath vs math.hypot magnitude ops lab: real ops/s for abs, polar, and phase, measured on Linux localhost today in this hands-on lab for SREs.
Summary1 Oct 20263 min read
Summary1 Oct 20264 min read