Skip to content

fix: time all URL parsers on the same inputs - #14

Open
lemire wants to merge 1 commit into
mainfrom
fix-benchmark-same-urls
Open

fix: time all URL parsers on the same inputs#14
lemire wants to merge 1 commit into
mainfrom
fix-benchmark-same-urls

Conversation

@lemire

@lemire lemire commented Aug 22, 2026

Copy link
Copy Markdown
Member

Summary

The top-100k URL benchmarks were not comparable. Each BenchmarkTop100* function break'd on the first parse error, and the three libraries reject different inputs:

  • goada and whatwg-url fail first at index 5063 (plain text, no scheme)
  • net/url continues until index 7828

So goada/whatwg-url were timed on 5,063 URLs while net/url was timed on 7,828 — and none of them ran the full dataset. The README then divided ns/op by ~100k, which made every library look ~20× faster than it was.

Changes

  • Parse every URL in the shared list, including ones that fail
  • Skip empty lines when loading top100.txt (6 lines; not URLs)
  • Keep parse results in sinks so the compiler cannot dead-code the calls
  • Fail the benchmark if the dataset failed to load

Remeasured numbers

Median of 7 runs (-benchtime=3s -count=7) on Apple M4 Max, 100,025 URLs:

Library ns/op (full dataset) ns/op per URL WHATWG
goada 58,533,792 585.2 yes
Go net/url 31,780,421 317.7 no
whatwg-url 322,011,608 3219.3 yes

Reproduce with:

go test -bench BenchmarkTop100 -run -

Stop breaking on the first parse error so goada, net/url, and
whatwg-url are measured on the full top-100k dataset. Skip empty
lines, keep parse results alive, and update README numbers from a
re-run on Apple M4 Max.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant