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 to uint would be still faster than the byte array comparison.
NetTools.Bits static class is nice example of LINQ usage, but it's really slow.
Possible improvement ideas:
IsIPv4MappedToIPv6IPAddress.GetHashCode()which is 32-bit number as ip address. Casting hash code touintwould be still faster than the byte array comparison.