3 ms·
It's an interesting phenomenon in "slowish" languages that people feel this way > This function [length] is implemented in the VM so it’s expected to be very,
by tel 12y ago
It's an interesting phenomenon in "slowish" languages that people feel this way
> This function [length] is implemented in the VM so it’s expected to be very, very fast.
Even being aware of the data structure and algorithmic bounds forced upon such a function, being "in the VM" indicates speed and a safe choice in using it.
Of course, as this post notes, that's sort of insane. O(N) is a big computation on a big list and it means that there's a chance of memory competition. High level language or otherwise, you can't ignore algorithmic complexity. That's just absurd.
It just feels like a weird quirk of Erlang's queue module. If you're mutable, then getting down to raw memory is probably a good idea. If you're doing this all with linked lists the dear god go read Okasaki and at least have an amortized constant queue pop!
- felixgallo 12y agoor at least read the erlang:queue() documentation which specifically references this case, outlines the rationale for why it is the way that it is, provides an Okasaki-style API, and references his book. http://erlang.org/doc/man/queue.html http://erlang.org/doc/man/queue.html