Last active
August 29, 2015 13:58
-
-
Save dacamp/10428396 to your computer and use it in GitHub Desktop.
Ruby 1.8 + GeoIP-C Benchmark
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'rubygems' | |
require 'mysql2' | |
require 'geoip' | |
require 'benchmark' | |
[..] | |
results = mysql.client.query(...) | |
[..] | |
Benchmark.bm do |x| | |
x.report("#{ '%06i' % 1} time :") { geodb.look_up(results.first['ip']) } | |
x.report("#{ '%06i' % 25} times:") { results.take(25).map{|r| geodb.look_up(r['ip']) } } | |
x.report("#{ '%06i' % 1000} times:") { results.take(1000).map{|r| geodb.look_up(r['ip']) } } | |
x.report("#{ '%06i' % 5000} times:") { results.take(5000).map{|r| geodb.look_up(r['ip']) } } | |
x.report("#{ '%06i' % 10000} times:") { results.take(10000).map{|r| geodb.look_up(r['ip']) } } | |
x.report("#{ '%06i' % 100000} times:") { results.take(100000).map{|r| geodb.look_up(r['ip']) } } | |
x.report("#{ '%06i' % 500000} times:") { results.take(500000).map{|r| geodb.look_up(r['ip']) } } | |
end | |
user system total real | |
000001 time : 0.000000 0.000000 0.000000 ( 0.005791) | |
000025 times: 0.000000 0.000000 0.000000 ( 0.001670) | |
001000 times: 0.020000 0.010000 0.030000 ( 0.089256) | |
005000 times: 0.170000 0.000000 0.170000 ( 0.547191) | |
010000 times: 1.560000 0.490000 2.050000 ( 6.133947) | |
100000 times: 11.230000 0.060000 11.290000 ( 12.130464) | |
500000 times: 61.400000 0.910000 62.310000 ( 78.016542) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment