From: Bill Kelly Date: 2008-02-20T18:08:03+09:00 Subject: Re: The Smallest Circle (#157) ------=_NextPart_000_0117_01C8735C.CD2F6540 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=original Content-Transfer-Encoding: 7bit From: "ThoML" > @bill >> Would be interesting to calculate how much my crude hack tends to >> deviate from the perfect solution(s). > > You might be more interested in speed. Hi Thomas, I wasn't able to benchmark your solution because I couldn't find the #combination method? These are the times I get running the other solutions, 10 runs of 1000 points each. Each run, every solution is fed the exact same point data. $ ruby 157_benchmark.rb user system total real FRANK 23.469000 0.297000 23.766000 ( 23.781000) JUSTIN 6.765000 0.000000 6.765000 ( 6.812000) LIONEL 5.704000 0.000000 5.704000 ( 5.703000) DOUG 3.797000 0.031000 3.828000 ( 3.829000) PHILIPP 1.390000 0.016000 1.406000 ( 1.422000) BILL 0.281000 0.000000 0.281000 ( 0.281000) Looks like my speed is good... Still curious how my accuracy compares though... :) (Benchmark code is attached...) Regards, Bill ------=_NextPart_000_0117_01C8735C.CD2F6540 Content-Type: application/octet-stream; name="157_benchmark.rb" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="157_benchmark.rb" require 'benchmark' module PHILIPP ; eval(File.read('157_philipp_hofmann.rb')) ; end module LIONEL ; eval(File.read('157_lionel_bouton.rb')) ; end module THOMAS ; eval(File.read('157_thomas_ml.rb')) ; end module DOUG ; eval(File.read('157_doug_seifert.rb')) ; end module FRANK ; eval(File.read('157_frank_fischer.rb')) ; end module JUSTIN ; eval(File.read('157_justin_ethier.rb')) ; end module BILL ; eval(File.read('157_smallest_circle.rb')) ; end namespaces = [ # THOMAS, # points.combination ?? FRANK, JUSTIN, LIONEL, DOUG, PHILIPP, BILL ] # Some folks implemented generate_samples differently, # but we want to run all solutions on the same dataset. # We'll use an implementation equivalent to that # provided by the quiz author: [rand, rand] num_runs = 10 num_samples = 1000 def generate_samples(mod, coords) coords.map {|xy| mod::Point.new(*xy)} end # Pregenerate different point data for successive runs. # (All solutions are fed the same point data per run.) pointsets = {} namespaces.each do |mod| pointsets[mod.name] = (1..num_runs).map do point_coords = (1..num_samples).map {[rand, rand]} generate_samples(mod, point_coords) end end solutions = {} namespaces.each {|mod| solutions[mod.name] = Class.new { include mod }.new} label_width = namespaces.map {|mod| mod.name.length}.max Benchmark.bm(label_width) do |x| namespaces.each do |mod| name = mod.name solution = solutions[name] x.report(name) do num_runs.times do |i| points = pointsets[name][i] solution.encircle(points) end end end end ------=_NextPart_000_0117_01C8735C.CD2F6540--