Skip to content

Instantly share code, notes, and snippets.

@okkez okkez/Gemfile
Created Nov 28, 2016

Embed
What would you like to do?
Benchmark for libmaxmind bindings
require "benchmark"
require "ipaddr"
require "geoip"
require "geoip2_compat"
require "maxminddb"
require "hive_geoip2"
require "maxmind_geoip2"
require "pp"
N = 8192
M = 10_000
#ips = N.times.map { IPAddr.new(rand(2**13) * 2**19, Socket::AF_INET).to_s }
geoip = GeoIP::City.new("./GeoLiteCity.dat", :memory, false)
geoip2_compat = GeoIP2Compat.new("./GeoLite2-City.mmdb")
mmdb = MaxMindDB.new("./GeoLite2-City.mmdb")
hive = Hive::GeoIP2.new("./GeoLite2-City.mmdb")
MaxmindGeoIP2.file("./GeoLite2-City.mmdb")
MaxmindGeoIP2.locale("ja")
Benchmark.bmbm do |x|
x.report("geoip") do
M.times do
geoip.look_up(IPAddr.new(rand(2**13) * 2**19, Socket::AF_INET).to_s)
end
end
x.report("geoip2_compat") do
M.times do
geoip2_compat.lookup(IPAddr.new(rand(2**13) * 2**19, Socket::AF_INET).to_s)
end
end
x.report("maxminddb (pure ruby)") do
M.times do
mmdb.lookup(IPAddr.new(rand(2**13) * 2**19, Socket::AF_INET).to_s)
end
end
x.report("hive") do
M.times do
hive.lookup(IPAddr.new(rand(2**13) * 2**19, Socket::AF_INET).to_s)
end
end
x.report("maxmind_geoip2") do
M.times do
MaxmindGeoIP2.locate(IPAddr.new(rand(2**13) * 2**19, Socket::AF_INET).to_s)
end
end
end if false
ip = IPAddr.new(rand(2**13) * 2**19, Socket::AF_INET).to_s
p ip
pp geoip.look_up(ip)
p "--"
pp geoip2_compat.lookup(ip)
#p "--"
#pp mmdb.lookup(ip)
p "--"
pp hive.lookup(ip)
p "--"
pp MaxmindGeoIP2.locate(ip)
hive.close
source "https://rubygems.org"
gem "maxmind_geoip2"
gem "maxminddb"
gem "hive_geoip2"
gem "geoip2_compat"
gem "geoip-c", require: "geoip"
$ bundle exec ruby bench.rb
Rehearsal ---------------------------------------------------------
geoip 0.080000 0.000000 0.080000 ( 0.082323)
geoip2_compat 0.060000 0.000000 0.060000 ( 0.062950)
maxminddb (pure ruby) 2.290000 0.000000 2.290000 ( 2.284960)
hive 0.230000 0.000000 0.230000 ( 0.226919)
maxmind_geoip2 0.630000 0.210000 0.840000 ( 0.848425)
------------------------------------------------ total: 3.500000sec
user system total real
geoip 0.080000 0.000000 0.080000 ( 0.075413)
geoip2_compat 0.060000 0.000000 0.060000 ( 0.063265)
maxminddb (pure ruby) 2.330000 0.000000 2.330000 ( 2.326974)
hive 0.250000 0.000000 0.250000 ( 0.242188)
maxmind_geoip2 0.650000 0.270000 0.920000 ( 0.926980)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.