Time a block of code with a context manager
Measure elapsed wall-clock time of a with-block using time.perf_counter.
Loading snippets…
15 snippets
Measure elapsed wall-clock time of a with-block using time.perf_counter.
Stream CSV rows as associative arrays using fgetcsv, without loading the whole file into memory.
Process a large list with at most N promises in flight at once, preserving result order.
Process many files concurrently with xargs -P, safely handling spaces and newlines in names.
Cache results by argument so expensive pure functions only run once per distinct input.
Memoize pure functions with a bounded least-recently-used cache and inspect or clear it.
Defer off-screen images and embeds with loading="lazy", while keeping the main image eager to protect LCP.
Reserve space for videos and images with aspect-ratio so the page does not jump while loading.
Run a function at most once per interval, calling immediately and again at the end of a burst.
Compute cumulative sums per group without self-joins using SUM() OVER (PARTITION BY ... ORDER BY ...).
Serve modern formats and the right image size per device, with explicit dimensions to prevent layout shift.
Page through large tables quickly and stably by filtering on the last seen sort key.