Skip to content

Commit

Permalink
Add benchmark script and performance section to readme
Browse files Browse the repository at this point in the history
  • Loading branch information
zachblock committed Jun 22, 2011
1 parent d48f010 commit 3c55c4f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
9 changes: 9 additions & 0 deletions README.markdown
Expand Up @@ -21,6 +21,15 @@ To test if a point is in the region you can either pass a class that responds to


If you want to use your own point class, just define `x` and `y` as methods that correspond to `longitude` and `latitude`. If you want to use your own point class, just define `x` and `y` as methods that correspond to `longitude` and `latitude`.


## Performance
It's definitely not going to beat a specialized system like PostGIS or SOLR, but it also doesn't have to go across the network to get results.
We've been using it successfully in critical paths in production with zero impact. Here's a benchmark checking 10,000 random points against the sample files included in the specs.

user system total real
colorado region 0.240000 0.010000 0.250000 ( 0.249663)
multi polygon region 0.610000 0.020000 0.630000 ( 0.631532)


## Pro Tip ## Pro Tip


You can make KML files easily on Google Maps by clicking "My Maps", drawing shapes and saving the map. Just copy the share link and add "&output=kml" to download the file.g You can make KML files easily on Google Maps by clicking "My Maps", drawing shapes and saving the map. Just copy the share link and add "&output=kml" to download the file.g
Expand Down
21 changes: 21 additions & 0 deletions script/benchmark.rb
@@ -0,0 +1,21 @@
#!/usr/bin/env ruby -w
require "spec/spec_helper"
require 'benchmark'

colorado_region = BorderPatrol.parse_kml(File.read('spec/support/colorado-test.kml'))
multi_polygon_region = BorderPatrol.parse_kml(File.read('spec/support/multi-polygon-test.kml'))
Benchmark.bm(20) do |x|
x.report("colorado region") do
10000.times do |i|
multiple = (rand(2) == 1) ? -1 : 1
colorado_region.contains_point?(rand * 180 * multiple, rand * 180 * multiple)
end
end

x.report("multi polygon region") do
10000.times do |i|
multiple = (rand(2) == 1) ? -1 : 1
multi_polygon_region.contains_point?(rand * 180 * multiple, rand * 180 * multiple)
end
end
end
3 changes: 0 additions & 3 deletions spec/spec_helper.rb
Expand Up @@ -3,6 +3,3 @@
Bundler.setup Bundler.setup


require 'border_patrol' require 'border_patrol'

RSpec.configure do |config|
end

0 comments on commit 3c55c4f

Please sign in to comment.