Closed
Description
using Chairmarks
import GeometryOps as GO, GeoInterface as GI
function _area(p::GI.LinearRing)
first_point = p.geom[1]
area = 0.0
for next_point in view(p.geom, 2:length(p.geom))
area += first_point[1] * next_point[2] - first_point[2] * next_point[1]
first_point = next_point
end
return area
end
_area(p::GI.Polygon) = if length(p.geom) == 1
_area(p.geom[1])
else
_area(p.geom[1]) - sum(_area, view(p.geom, 2:length(p.geom)))
end
p = GI.Polygon([GI.LinearRing([(0, 0), (0,1), (1, 1), (1, 0), (0, 0)])])
@be GO.area($p) # ~6 ns
@be _area($p) # ~7 ns
# These two are at least equivalent - showing that `apply` and `applyreduce` are indeed cost-free.
@be GO.area($([p, p])) # ~17 ns, 1 allocation
@be sum($_area, $([p, p])) # ~15 ns, no allocations
# So there is work to do here.
We need to isolate and remove this allocation!
Metadata
Metadata
Assignees
Labels
No labels