Target: 1.4.0 (Tier 1 — earn the benchmark)
bytes_to_mac() (_base.py:48) is:
return":".join(format(octet, "02x") foroctetindata)
That runs seven generator steps, six format() calls and a join per
address — twice per Ethernet frame, plus once per NDP link-layer option
and per ARP hardware address. In a corpus profile the generator
expression alone accounts for 88,200 calls.
bytes.hex() has taken a separator argument since Python 3.8 and does
the whole thing in one C call.
Measured
300,000 calls: 0.350 s → 0.021 s — 16.5× faster.
What to do
returnbytes(data).hex(":")The bytes() wrapper keeps memoryview input working. Output is
identical: lowercase, colon-separated.
Acceptance criteria
Target: 1.4.0 (Tier 1 — earn the benchmark)
bytes_to_mac()(_base.py:48) is:That runs seven generator steps, six
format()calls and ajoinperaddress — twice per Ethernet frame, plus once per NDP link-layer option
and per ARP hardware address. In a corpus profile the generator
expression alone accounts for 88,200 calls.
bytes.hex()has taken a separator argument since Python 3.8 and doesthe whole thing in one C call.
Measured
300,000 calls: 0.350 s → 0.021 s — 16.5× faster.
What to do
The
bytes()wrapper keepsmemoryviewinput working. Output isidentical: lowercase, colon-separated.
Acceptance criteria
memoryviewinput still works.