Skip to content

Render MAC addresses with bytes.hex(":") #83

Description

@EONRaider

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

  • Output is byte-for-byte identical for all existing tests.
  • memoryview input still works.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions