[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: [QUIZ] IP to Country (#139

steve d

9/20/2007 3:52:00 AM

I did some benchmarking of my own. This one tests out the performance of a single lookup. I only ran this on solutions which work with IpToCountry.csv out of the box (aka do no prep work).This benchmark ran each solution 1000 times with random IPs (invoking a new ruby instance on each run).-bash-2.05b$ ruby bm.rbsorted by real time[["steved.rb", 10.5210349559784], ["adam.rb", 10.817939043045], ["justin.rb", 11.6265380382538], ["james.rb", 12.3434510231018], ["eugene.rb", 12.9024469852448], ["jesus.rb", 13.2812840938568], ["erik.rb", 13.3421401977539], ["simon.rb", 14.0733840465546]]sorted by sys time[["simon.rb", 0.796875], ["steved.rb", 1.3046875], ["adam.rb", 1.5078125], ["justinrb", 1.515625], ["jesus.rb", 1.765625], ["eugene.rb", 2.265625], ["erik.rb", 2.421875], ["james.rb", 2.4609375]]sorted by user time[["simon.rb", 0.078125], ["eugene.rb", 0.09375], ["jesus.rb", 0.109375], ["steved.rb", 0.1171875], ["justin.rb", 0.1171875], ["jamesrb", 0.125], ["adam.rb", 0.125], ["erik.rb", 0.1953125]]Here's the benchmark source:require 'benchmark'require 'pp'random_ips = Array.new(1000).map { Array.new(4).map {rand(256)}.join('.') }sols = Dir["*.rb"] - [$0]times = {}sols.each do |fn| stats = Benchmark.measure do random_ips.each do |ip| %x{ ruby #{fn} #{ip} } end end times[fn] = statsendsort_times = proc { |m| times.sort_by{|(k,v)| v.send(m)}.map{|(k,v)| [k, v.send(m)]} }puts "sorted by real time"pp sort_times[:real]putsputs "sorted by sys time"pp sort_times[:stime]putsputs "sorted by user time"pp sort_times[:utime]Also, Adam, your solution seems to give incorrect answers sometimes, I noticed 33.33.33.33 and 88.88.88.88 both gave Not Found where as all the other solutions gave US and NO respectively.- steve

1 Answer

Bill Kelly

9/20/2007 5:00:00 AM

0


From: "steve d" <oksteev@yahoo.com>
>
> I did some benchmarking of my own. This one tests out the
> performance of a single lookup. I only ran this on solutions
> which work with IpToCountry.csv out of the box (aka do no prep work).

Cool. I guess mine was overlooked but it also does no prep work:
http://groups.google.com/group/comp.lang.ruby/msg/6162dae2bcf1bc3f?dm...


Regards,

Bill