Sha256: 41207c136f6ef4be825f617e4fd3a4af74e41a76d7cb517a0e0e457f15337a6b
Contents?: true
Size: 1.4 KB
Versions: 1
Compression:
Stored size: 1.4 KB
Contents
require "mongoid/spec_helper" require 'benchmark' Address.collection.create_index([['location', Mongo::GEO2D]], :min => -180, :max => 180) def delta (rand(10000) / 10000.0) - 0.5 end describe 'Mongoid spherical geoNear distance calculations' do context "Spherical mode distance" do before do Mongoid::Geo.spherical = true @center = Address.create(:location => {:lat => 31.5, :lng => -121.5}, :city => 'center') 5000.times do Address.create(:location => {:lat => 31 + delta, :lng => -121 + delta}) end end context 'Mongo DB < 1.7' do before do Mongoid::Geo.mongo_db_version = 1.6 end it "calculates distance using ruby Haversine code" do Mongoid::Geo.mongo_db_version.should == 1.6 Mongoid::Geo.spherical.should be_true puts Benchmark.measure { Address.geoNear @center.location, :location, :unit => :km } end end context 'Mongo DB 1.8' do before do Mongoid::Geo.mongo_db_version = 1.8 Mongoid::Geo.spherical = true end it "calculate distance using Mongo 1.8 native distance calculation" do Mongoid::Geo.mongo_db_version.should == 1.8 Mongoid::Geo.spherical.should be_true puts Benchmark.measure { Address.geoNear @center.location, :location, :unit => :km, :mode => :sphere } end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
mongoid_geo-0.6.0 | spec/mongoid/db_v1_8/geonear_benchmark_spec.rb |