Skip to content
Browse files

Add benchmark script and performance section to readme

  • Loading branch information...
1 parent d48f010 commit 3c55c4f9c4d33f39c83026c0e4a27d2e280b5df7 Zach Brock committed Jun 22, 2011
Showing with 30 additions and 3 deletions.
  1. +9 −0 README.markdown
  2. +21 −0 script/benchmark.rb
  3. +0 −3 spec/spec_helper.rb
View
9 README.markdown
@@ -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`.
+## 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
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
View
21 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
View
3 spec/spec_helper.rb
@@ -3,6 +3,3 @@
Bundler.setup
require 'border_patrol'
-
-RSpec.configure do |config|
-end

0 comments on commit 3c55c4f

Please sign in to comment.
Something went wrong with that request. Please try again.