Skip to content

Instantly share code, notes, and snippets.

@bluemonk
Created August 10, 2010 13:26
Show Gist options
  • Select an option

  • Save bluemonk/517250 to your computer and use it in GitHub Desktop.

Select an option

Save bluemonk/517250 to your computer and use it in GitHub Desktop.
n = 50_000
ipaddr = IPAddr.new("192.168.10.100/32")
ipaddress = IPAddress::IPv4.new("192.168.10.100/32")
Benchmark.bm do|b|
b.report("ipaddr ") do
n.times { IPAddr.new("192.168.10.0/24").include?(ipaddr) }
end
b.report("ipaddress parse ") do
n.times { IPAddress.parse("192.168.10.0/24").include?(ipaddress)}
end
b.report("ipaddress ipv4 ") do
n.times { IPAddress::IPv4.new("192.168.10.0/24").include?(ipaddress) }
end
end
user system total real
ipaddr 18.680000 5.800000 24.480000 ( 35.334625)
ipaddress parse 17.190000 1.280000 18.470000 ( 23.506759)
ipaddress ipv4 16.590000 1.250000 17.840000 ( 21.809339)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment