bench.rb in ipconverter-0.1.0 vs bench.rb in ipconverter-0.1.1
- old
+ new
@@ -8,12 +8,12 @@
def ip_to_i2(ip)
octets = ip.split('.').map(&:to_i)
octets[3] +
octets[2] * 256 +
- octets[1] * 256*256 +
- octets[0] * 256*256*256
+ octets[1] * 256 * 256 +
+ octets[0] * 256 * 256 * 256
end
def ipaddr_to_i(ip)
IPAddr.new(ip).to_i
end
@@ -27,15 +27,14 @@
end
end
end
end
-puts "iterations: " + ips.length
+puts 'iterations: ' + ips.length
Benchmark.bmbm do |x|
x.report('IPAddr#to_i') { ips.each { |ip| IPAddr.new(ip).to_i } }
x.report('pack/unpack') { ips.each { |ip| ip_to_i(ip) } }
x.report('split/multiply') { ips.each { |ip| ip_to_i2(ip) } }
- x.report('C split/multiply') { ips.each {|ip| IpConverter.str_to_int(ip) } }
- x.report('noop') { ips.each {|ip| ip } }
+ x.report('C split/multiply') { ips.each { |ip| IpConverter.str_to_int(ip) } }
+ x.report('noop') { ips.each { |ip| ip } }
end
-