-
Notifications
You must be signed in to change notification settings - Fork 55
/
bench.rb
35 lines (28 loc) · 959 Bytes
/
bench.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#
# Just for fun, benchmarking Pure Ruby GeoRuby against RGeo.
#
# !/usr/bin/env ruby
require 'benchmark'
require 'geo_ruby'
require 'rgeo'
COUNT = 100_000
fac = RGeo::Cartesian.factory
def t(text)
puts "\n\n#{' ' * (53 - text.size)}#{text}\n"
end
t 'Point.new!'
Benchmark.bmbm do |x|
x.report('Georuby') { COUNT.times { x = GeoRuby::SimpleFeatures::Point.from_x_y(1, 1) } }
x.report('RGeo') { COUNT.times { x = fac.point(1, 1) } }
end
t 'Point.xy!'
gpoint, rpoint = GeoRuby::SimpleFeatures::Point.from_x_y(1, 1), fac.point(1, 1)
Benchmark.bmbm do |x|
x.report('Georuby') { COUNT.times { x, y = gpoint.x, gpoint.y } }
x.report('RGeo') { COUNT.times { x, y = rpoint.x, rpoint.y } }
end
t 'Distance Haversine Formula'
Benchmark.bmbm do |x|
x.report('Georuby') { COUNT.times { x = GeoRuby::SimpleFeatures::Point.from_x_y(1, 1); x.spherical_distance(x) } }
x.report('RGeo') { COUNT.times { x = fac.point(1, 1); x.distance(x) } }
end