Skip to content

Instantly share code, notes, and snippets.

@vhermecz
Created January 27, 2021 10:59
Show Gist options
  • Save vhermecz/7edf4c7c113e7a2f6b9705064eff07e8 to your computer and use it in GitHub Desktop.
Save vhermecz/7edf4c7c113e7a2f6b9705064eff07e8 to your computer and use it in GitHub Desktop.
Benchmark some RGeo operations
#!/usr/bin/env ruby
require 'benchmark/ips'
require 'rgeo'
Benchmark.ips do |x|
x.time = 5
x.warmup = 2
x.report("blank-1") do |times|
i=0
while i < times
i += 1
end
end
x.report("blank-2") do |times|
times.times do
end
end
x.report("parser-default") do |times|
i=0
while i < times
RGeo::WKRep::WKTParser.new(nil, :support_ewkt => false)
i += 1
end
end
x.report("factory-cart") do |times|
i=0
while i < times
RGeo::Cartesian.factory(:uses_lenient_assertions => true)
i += 1
end
end
x.report("factory-mercat") do |times|
i=0
while i < times
RGeo::Geographic.simple_mercator_factory
i += 1
end
end
x.report("parser-mercat") do |times|
i=0
while i < times
factory = RGeo::Geographic.simple_mercator_factory
RGeo::WKRep::WKTParser.new(factory, :support_ewkt => false)
i += 1
end
end
generator = RGeo::WKRep::WKTGenerator.new()
poly_large = "POLYGON ((34.644013 -12.259757, 34.643305 -12.259761, 34.643305 -12.259639, 34.643146 -12.259453, 34.643142 -12.259476, 34.643078 -12.259514, 34.642938 -12.259348, 34.642958 -12.259336, 34.642945 -12.259319, 34.642966 -12.259307, 34.642944 -12.259282, 34.642985 -12.259259, 34.642926 -12.259189, 34.642926 -12.259047, 34.642946 -12.25903, 34.642966 -12.259031, 34.642965 -12.258923, 34.643433 -12.258363, 34.643413 -12.258351, 34.6434 -12.258367, 34.643311 -12.258315, 34.643418 -12.258187, 34.643525 -12.25825, 34.643558 -12.25821, 34.643538 -12.258198, 34.643553 -12.258181, 34.643574 -12.258193, 34.643649 -12.258105, 34.644205 -12.258199, 34.644186 -12.258283, 34.644221 -12.258329, 34.644246 -12.258333, 34.644225 -12.258435, 34.644201 -12.258432, 34.644169 -12.258591, 34.64396 -12.25884, 34.64396 -12.258859, 34.643999 -12.258859, 34.643999 -12.258832, 34.644091 -12.258726, 34.644133 -12.258726, 34.644134 -12.258658, 34.644166 -12.258658, 34.644165 -12.258726, 34.644182 -12.258758, 34.644194 -12.258758, 34.644194 -12.258782, 34.644182 -12.258782, 34.644175 -12.258803, 34.644196 -12.258803, 34.644195 -12.258892, 34.644176 -12.258892, 34.644175 -12.258983, 34.644167 -12.258982, 34.644166 -12.259013, 34.644186 -12.259025, 34.644185 -12.259053, 34.644177 -12.259068, 34.644112 -12.259067, 34.644112 -12.259059, 34.644078 -12.259059, 34.644078 -12.259066, 34.643787 -12.259063, 34.643787 -12.259125, 34.643962 -12.259126, 34.643975 -12.259117, 34.644181 -12.25912, 34.64418 -12.259215, 34.644183 -12.259215, 34.644183 -12.259333, 34.644177 -12.259333, 34.644177 -12.259381, 34.644164 -12.259381, 34.644163 -12.259398, 34.644071 -12.259397, 34.643983 -12.259297, 34.643961 -12.259296, 34.643961 -12.259317, 34.644049 -12.259416, 34.644057 -12.259409, 34.644086 -12.259441, 34.644086 -12.25947, 34.644074 -12.259482, 34.644132 -12.259482, 34.644131 -12.259517, 34.644074 -12.259517, 34.644073 -12.259569, 34.644088 -12.259569, 34.644088 -12.259635, 34.644066 -12.259635, 34.644013 -12.259676, 34.644013 -12.259757))"
poly_small = "POLYGON ((-78.70954661451728 43.28179494978209, -78.70942611907596 43.28183755710857, -78.7093818513938 43.28177120006014, -78.70950234167337 43.2817285945124, -78.70954661451728 43.28179494978209))"
factory = RGeo::Geographic.simple_mercator_factory
parser = RGeo::WKRep::WKTParser.new(factory, :support_ewkt => false)
x.report("parse-mercat-large") do |times|
i=0
while i < times
parser.parse(poly_large)
i += 1
end
end
x.report("parse-mercat-small") do |times|
i=0
while i < times
parser.parse(poly_small)
i += 1
end
end
obj_large = parser.parse(poly_large)
obj_small = parser.parse(poly_small)
x.report("generator-large") do |times|
i=0
while i < times
generator.generate(obj_large)
i += 1
end
end
x.report("generator-small") do |times|
i=0
while i < times
generator.generate(obj_small)
i += 1
end
end
parser = RGeo::WKRep::WKTParser.new(nil, :support_ewkt => false)
x.report("parse-default-large") do |times|
i=0
while i < times
parser.parse(poly_large)
i += 1
end
end
x.report("parse-default-small") do |times|
i=0
while i < times
parser.parse(poly_small)
i += 1
end
end
obj_large = parser.parse(poly_large)
obj_small = parser.parse(poly_small)
x.report("generator-large-d") do |times|
i=0
while i < times
generator.generate(obj_large)
i += 1
end
end
x.report("generator-small-d") do |times|
i=0
while i < times
generator.generate(obj_small)
i += 1
end
end
factory = RGeo::Cartesian.factory(:uses_lenient_assertions => true)
parser = RGeo::WKRep::WKTParser.new(factory, :support_ewkt => false)
x.report("parse-cartesian-lenient-large") do |times|
i=0
while i < times
parser.parse(poly_large)
i += 1
end
end
x.report("parse-cartesian-lenient-small") do |times|
i=0
while i < times
parser.parse(poly_small)
i += 1
end
end
x.compare!
end
Warming up --------------------------------------
blank-1 4.239M i/100ms
blank-2 2.245M i/100ms
parser-default 82.518k i/100ms
factory-cart 11.790k i/100ms
factory-mercat 2.388k i/100ms
parser-mercat 2.565k i/100ms
parse-mercat-large 59.000 i/100ms
parse-mercat-small 708.000 i/100ms
generator-large 444.000 i/100ms
generator-small 3.829k i/100ms
parse-default-large 59.000 i/100ms
parse-default-small 701.000 i/100ms
generator-large-d 444.000 i/100ms
generator-small-d 3.815k i/100ms
parse-cartesian-lenient-large
57.000 i/100ms
parse-cartesian-lenient-small
718.000 i/100ms
Calculating -------------------------------------
blank-1 40.370M (± 3.8%) i/s - 203.465M in 5.047613s
blank-2 19.072M (±11.1%) i/s - 94.311M in 5.011632s
parser-default 730.725k (± 5.5%) i/s - 3.713M in 5.097329s
factory-cart 133.967k (± 6.1%) i/s - 672.030k in 5.036193s
factory-mercat 38.265k (± 6.5%) i/s - 191.040k in 5.014115s
parser-mercat 36.078k (± 7.2%) i/s - 182.115k in 5.074092s
parse-mercat-large 609.736 (± 5.1%) i/s - 3.068k in 5.044455s
parse-mercat-small 7.508k (± 4.8%) i/s - 37.524k in 5.009584s
generator-large 4.703k (± 4.8%) i/s - 23.532k in 5.015371s
generator-small 41.384k (± 4.6%) i/s - 206.766k in 5.007053s
parse-default-large 580.325 (± 6.9%) i/s - 2.891k in 5.005467s
parse-default-small 7.505k (± 5.2%) i/s - 37.854k in 5.057356s
generator-large-d 4.722k (± 4.3%) i/s - 23.976k in 5.086848s
generator-small-d 41.350k (± 6.2%) i/s - 206.010k in 5.002365s
parse-cartesian-lenient-large
602.555 (± 6.3%) i/s - 3.021k in 5.034069s
parse-cartesian-lenient-small
7.574k (± 5.5%) i/s - 38.054k in 5.039512s
Comparison:
blank-1: 40370312.6 i/s
blank-2: 19071547.3 i/s - 2.12x (± 0.00) slower
parser-default: 730725.3 i/s - 55.25x (± 0.00) slower
factory-cart: 133967.0 i/s - 301.35x (± 0.00) slower
generator-small: 41384.3 i/s - 975.50x (± 0.00) slower
generator-small-d: 41350.5 i/s - 976.30x (± 0.00) slower
factory-mercat: 38265.4 i/s - 1055.01x (± 0.00) slower
parser-mercat: 36077.8 i/s - 1118.98x (± 0.00) slower
parse-cartesian-lenient-small: 7573.7 i/s - 5330.35x (± 0.00) slower
parse-mercat-small: 7507.7 i/s - 5377.17x (± 0.00) slower
parse-default-small: 7505.4 i/s - 5378.80x (± 0.00) slower
generator-large-d: 4722.3 i/s - 8548.88x (± 0.00) slower
generator-large: 4703.3 i/s - 8583.47x (± 0.00) slower
parse-mercat-large: 609.7 i/s - 66209.49x (± 0.00) slower
parse-cartesian-lenient-large: 602.6 i/s - 66998.54x (± 0.00) slower
parse-default-large: 580.3 i/s - 69565.05x (± 0.00) slower
root@1a470382abac:/railsapp#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment