Skip to content

Comparison performance leaks in Contains #38

@Menur

Description

@Menur

NetTools.Bits static class is nice example of LINQ usage, but it's really slow.

Possible improvement ideas:

  1. You can get like 33% less time spent on this when you use for cycles.
  2. You can even optimize IPv6 comparison for IPv4ToIPv6 mapped addresses to reduce number of iterations from 16 to 4.
  3. You can completely avoid some comparisons for IPv6 by checking IsIPv4MappedToIPv6
  4. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions