How we made Python's packaging library 3x faster

(iscinumpy.dev)

33 points | by rbanffy 3 days ago

2 comments

  • djoldman 48 minutes ago
    > _canonicalize_table = str.maketrans( "ABCDEFGHIJKLMNOPQRSTUVWXYZ_.", "abcdefghijklmnopqrstuvwxyz--", )

    > ...

    > value = name.translate(_canonicalize_table)

    > while "--" in value:

    > value = value.replace("--", "-")

    translate can be wildly fast compared to some commonly used regexes or replacements.

    • teaearlgraycold 21 minutes ago
      I would expect however that a regex replacement would be much faster than your N^2 while loop.
  • zahlman 3 days ago