On Tue, Apr 12, 2016 at 3:43 AM, DNF <[email protected]> wrote:
> But what if you do have a very small number of elements? Let's say I am
> working with 2D or 3D points and wonder whether to represent them as
> vectors, tuples or a custom type, like
>
> immutable Point2D{T<:Real}
>     x::T
>     y::T
> end
> Base.(:+){T}(p1::Point2D{T}, p2::Point2D{T}) = Point2D(p1.x+p2.x, p1.y+p2.y)

This is essentially equivalent (performance-wise) to using a tuple.

The main difference between small arrays and small tuples, if they
hold bitstypes (such as integers for floating-point numbers) seems to
me that arrays require heap allocation, while tuples do not. That can
lead to a significant performance difference, in particular if they
are used as elements of a large array, or in a loop that is executed
often.

-erik

-- 
Erik Schnetter <[email protected]>
http://www.perimeterinstitute.ca/personal/eschnetter/

Reply via email to