Sha256: d24dde6c99eab07cdfa868eb687d9ad442d5f7bb9c4f8871998cbffe00e9e707

Contents?: true

Size: 1.52 KB

Versions: 2

Compression:

Stored size: 1.52 KB

Contents

#!/usr/bin/env ruby
#
# Just for fun
#
$: << File.expand_path("../../lib", __FILE__)

require 'mongoid/geospatial'

Mongoid.configure do |config|
  config.connect_to("mongoid_geospatial_bench")
end

Mongoid::Geospatial.with_georuby!
Mongoid::Geospatial.with_rgeo!

class NoGeo
  include Mongoid::Document
  field :name
end

class Rider
  include Mongoid::Document
  include Mongoid::Geospatial
  field :name
end

class Cafe
  include Mongoid::Document
  include Mongoid::Geospatial
  field :name
  field :spot, type: Point
end

Mongoid.purge!
# [NoGeo, Rider, Cafe].each(&:delete_all)

Benchmark.bmbm do |b|
  [100, 1000, 3000].each do |t|
    nogeo, cafes = [], []
    b.report("#{t} W NoGeo") do
      t.times { nogeo << NoGeo.create(name: 'Boring').id }
    end
    b.report("#{t} W Rider") { t.times { Rider.create(name: 'Munro') } }

    b.report("#{t} W Cafe ") do
      t.times { cafes << Cafe.create(name: 'Bacco', spot: [3,3]).id }
    end
    # puts "---"
    b.report("#{t} R NoGeo") { nogeo.each { |id| NoGeo.find(id) }}
    # b.report("#{t} R Rider") { t.times { Rider.create(name: 'Munro') } }
    b.report("#{t} R Cafe ") { cafes.each { |id| Cafe.find(id) }}
    b.report("#{t} R Cafe Georuby") { cafes.each { |id| Cafe.find(id).spot.to_geo }}
    b.report("#{t} R Cafe RGeo") { cafes.each { |id| Cafe.find(id).spot.to_rgeo }}
  end
  b.report("R Cafe GeoRuby") do
    cafe = Cafe.first
    1_000_000.times { cafe.spot.to_geo }
  end
  b.report("R Cafe RGeo") do
    cafe = Cafe.first
    1_000_000.times { cafe.spot.to_rgeo }
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mongoid-geospatial-4.0.1 bench/bench
mongoid-geospatial-4.0.0 bench/bench