Skip to content

Instantly share code, notes, and snippets.

@okkez okkez/Gemfile
Created Apr 18, 2017

Embed
What would you like to do?
Benchmark for geoip2_c
require "benchmark"
require "ipaddr"
require "geoip"
require "geoip2_compat"
require "maxminddb"
require "hive_geoip2"
require "maxmind_geoip2"
require "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")
geoip2 = GeoIP2::Database.new("./GeoLite2-City.mmdb")
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
x.report("geoip2_c") do
M.times do
geoip2.lookup(IPAddr.new(rand(2**13) * 2**19, Socket::AF_INET).to_s)
end
end
end # if false
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
end
source "https://rubygems.org"
gem "maxmind_geoip2"
gem "maxminddb"
gem "hive_geoip2"
gem "geoip2_compat"
gem "geoip-c", require: "geoip"
gem "geoip2_c", require: "geoip2"
GEM
remote: https://rubygems.org/
specs:
geoip-c (0.9.1)
geoip2_c (0.2.0)
geoip2_compat (0.0.3)
hive_geoip2 (0.1.2)
maxmind_geoip2 (0.0.8)
maxminddb (0.1.12)
PLATFORMS
ruby
DEPENDENCIES
geoip-c
geoip2_c
geoip2_compat
hive_geoip2
maxmind_geoip2
maxminddb
BUNDLED WITH
1.14.6
$ bundle exec ruby bench.rb
Rehearsal ---------------------------------------------------------
geoip 0.140000 0.000000 0.140000 ( 0.147379)
geoip2_compat 0.110000 0.010000 0.120000 ( 0.108135)
maxminddb (pure ruby) 4.310000 0.000000 4.310000 ( 4.320897)
hive 0.320000 0.000000 0.320000 ( 0.321934)
maxmind_geoip2 1.240000 0.320000 1.560000 ( 1.561630)
geoip2_c 0.070000 0.000000 0.070000 ( 0.067715)
------------------------------------------------ total: 6.520000sec
user system total real
geoip 0.140000 0.000000 0.140000 ( 0.142973)
geoip2_compat 0.160000 0.000000 0.160000 ( 0.162996)
maxminddb (pure ruby) 4.650000 0.000000 4.650000 ( 4.654088)
hive 0.310000 0.000000 0.310000 ( 0.308363)
maxmind_geoip2 1.350000 0.430000 1.780000 ( 1.780049)
geoip2_c 0.080000 0.010000 0.090000 ( 0.078209)
bundle exec ruby bench.rb 13.26s user 0.83s system 99% cpu 14.134 total
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.