houseabsolute / Data-Validate-IP

IPv4 and IPv6 validation methods
https://metacpan.org/release/Data-Validate-IP/
Other
4 stars 1 forks source link

Provided optimized is_X_ip subs when inet_pton is available #8

Closed oschwald closed 7 years ago

oschwald commented 7 years ago

Benchmark when inet_pton is available:

$ perl  -Ilib bench/test 
Benchmark: timing 2000 iterations of is_private_ipv4, is_public_ipv4...
is_private_ipv4:  1 wallclock secs ( 0.70 usr +  0.00 sys =  0.70 CPU) @ 2857.14/s (n=2000)
is_public_ipv4:  2 wallclock secs ( 1.55 usr +  0.00 sys =  1.55 CPU) @ 1290.32/s (n=2000)
Benchmark: timing 2000 iterations of is_private_ipv6, is_public_ipv6...
is_private_ipv6:  0 wallclock secs ( 0.54 usr +  0.00 sys =  0.54 CPU) @ 3703.70/s (n=2000)
is_public_ipv6:  1 wallclock secs ( 0.54 usr +  0.00 sys =  0.54 CPU) @ 3703.70/s (n=2000)

Benchmark using old code without it:

$ DVI_NO_SOCKET=1 perl -Ilib bench/test 
Benchmark: timing 2000 iterations of is_private_ipv4, is_public_ipv4...
is_private_ipv4: 13 wallclock secs (13.16 usr +  0.43 sys = 13.59 CPU) @ 147.17/s (n=2000)
is_public_ipv4: 26 wallclock secs (24.94 usr +  0.44 sys = 25.38 CPU) @ 78.80/s (n=2000)
Benchmark: timing 2000 iterations of is_private_ipv6, is_public_ipv6...
is_private_ipv6:  1 wallclock secs ( 1.60 usr +  0.00 sys =  1.60 CPU) @ 1250.00/s (n=2000)
is_public_ipv6:  2 wallclock secs ( 1.62 usr +  0.00 sys =  1.62 CPU) @ 1234.57/s (n=2000)
autarch commented 7 years ago

Merged from the CLI. Thanks!