ipaddressrange
ipaddressrange copied to clipboard
Comparison performance leaks in Contains
NetTools.Bits static class is nice example of LINQ usage, but it's really slow.
Possible improvement ideas:
- You can get like 33% less time spent on this when you use for cycles.
- You can even optimize IPv6 comparison for IPv4ToIPv6 mapped addresses to reduce number of iterations from 16 to 4.
- You can completely avoid some comparisons for IPv6 by checking
IsIPv4MappedToIPv6 - For the IPv4 address family you can use
IPAddress.GetHashCode()which is 32-bit number as ip address. Casting hash code touintwould be still faster than the byte array comparison.
Thank you for your advices!
Could you make those advices as a real code, and send to me as pull requests?
I'll not have enough time to spent improving this library in these days.
If you send pull requests, it will be helpful for the community, I think.
I can't promise that merge your pull requests certainly at this time, but I'll consider well.
I published v.3.2.0 package.
Thanks @Menur 👍