Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comparison performance leaks in Contains #38

Open
Menur opened this issue Apr 13, 2018 · 2 comments
Open

Comparison performance leaks in Contains #38

Menur opened this issue Apr 13, 2018 · 2 comments

Comments

@Menur
Copy link
Contributor

Menur commented Apr 13, 2018

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.
@jsakamoto
Copy link
Owner

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.

@jsakamoto
Copy link
Owner

I published v.3.2.0 package.

Thanks @Menur 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants