jsakamoto / ipaddressrange

.NET Class Library for range of IP address, both IPv4 and IPv6.
Mozilla Public License 2.0
368 stars 71 forks source link

Parsing performance #9

Open yahorsi opened 9 years ago

yahorsi commented 9 years ago

Hi, thanks for the great lib, the ONLY for the ranges!!! Really really useful.

The IP ranges mught be used on some really hot paths in the app, so, did you ever consider replacing Regex.Match with something more robust & fast?

jsakamoto commented 9 years ago

I feel it is good idea about improvement to more faster parsing IP range text, I agree.

But I don't have enough my resouce (my private time), and more important point, I have no skill to how to coding more faster parsing :sob:

Could you improve this issue and send me pull request? Or can you find anybody to improve this issue?

P.S. I have already Unit Test suite, so these refactoring can feel free to apply, and safety :)

gregmac commented 9 years ago

Regex is very fast, and the use of regex here I'd say is appropriate. It could be made slightly faster, in some cases, by declaring static regex properties rather than in-line parameters, but even as-is, the compiled regular expressions are cached. Good reference about this: [https://msdn.microsoft.com/en-us/library/gg578045%28v=vs.110%29.aspx](Best Practices for Regular Expressions in the .NET Framework).

Now, if you're suggesting something other than regex, my gut reaction is that it's the wrong way to go. There are a wide range of inputs, so anything that can handle all of them is going to be complex, and complex flow is hard to make robust.

That said, the way forward is to make a pull request and include some comparative benchmarks showing the improvement. :)

llCorvinSll commented 8 years ago

for example, IPAddress class use native system calls for parsing IPs, but for quick googling dont tell me 1) native method for network 2) this solution is hard to implement and make cross-platform