Skip to content

Instantly share code, notes, and snippets.

@SamSaffron
Created October 4, 2018 06:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SamSaffron/4b9c01b10b1627874eec2aa51b75feaa to your computer and use it in GitHub Desktop.
Save SamSaffron/4b9c01b10b1627874eec2aa51b75feaa to your computer and use it in GitHub Desktop.
# playing with search ...
require_relative '../rerunner/rerunner.rb'
require 'maxminddb'
require 'ipaddr'
# $LOAD_PATH.unshift('/home/sam/Source/memory_profiler/lib')
require 'memory_profiler'
@rand = Random.new(123456)
ips = (0..100).map do
IPAddr.new(@rand.rand(2**32), Socket::AF_INET).to_s
end
countries = []
dbs = []
MemoryProfiler.report do
db = MaxMindDB.new('./GeoLite2-City.mmdb', MaxMindDB::LOW_MEMORY_FILE_READER)
dbs << db
ips.each do |ip|
countries << db.lookup(ip).country
end
end.pretty_print(detailed_report: false, retained_strings: 0, allocated_strings: 0)
MemoryProfiler.report do
db = MaxMindDB.new('./GeoLite2-City.mmdb')
dbs << db
ips.each do |ip|
countries << db.lookup(ip).country
end
end.pretty_print(detailed_report: false, retained_strings: 0, allocated_strings: 0)
# Total allocated: 5178841 bytes (118759 objects)
# Total retained: 121235 bytes (2115 objects)
#
# Total allocated: 62659823 bytes (118756 objects)
# Total retained: 57733098 bytes (2112 objects)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment