ipaddress: Speed up IPv4Address.ipv6_mapped#119814
Open
jstasiak wants to merge 1 commit intopython:mainfrom
Open
ipaddress: Speed up IPv4Address.ipv6_mapped#119814jstasiak wants to merge 1 commit intopython:mainfrom
jstasiak wants to merge 1 commit intopython:mainfrom
Conversation
A random find from my side, I was going through this code when I noticed
some unnecessary conversions happening.
Nice performance improvement basically for free (numbers from my M1 Pro
laptop):
In [1]: from ipaddress import IPv4Address, IPv6Address
In [2]: v4 = IPv4Address('10.0.0.1')
In [3]: IPv6Address(f'::ffff:{v4}') == IPv6Address((0xffff << 32) + v4._ip)
Out[3]: True
In [4]: %timeit IPv6Address(f'::ffff:{v4}')
3.63 µs ± 12 ns per loop (mean ± std. dev. of 7 runs, 100,000 loops each)
In [5]: %timeit IPv6Address((0xffff << 32) + v4._ip)
184 ns ± 0.413 ns per loop (mean ± std. dev. of 7 runs, 10,000,000 loops each)
Contributor
Author
|
I think this is small enough to not need an issue number. Since this is a 3.13+ feature I don't believe a news entry is needed either. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A random find from my side, I was going through this code when I noticed some unnecessary conversions happening.
Nice performance improvement basically for free (numbers from my M1 Pro laptop):