Enum.take/2 and Enum.drop/2 weird performance

For my purposes I’ve settled on using Enum.split/2 rather than either take/2 or drop/2. I was just confused as to why there’s such a discrepancy in the performance of these two functions.

What I mean is, why wouldn’t an implementation of drop and take when n is less than 0 look like:

def take(list, n) when n < 0 do
   drop(list, n)
end

def drop(list, n) when n < 0 do
   take(list, n)
end

Shouldn’t this theoretically close the performance gap?

1 Like