[erlang-questions] Erlang list equality check question
mko_io
me@REDACTED
Sat Mar 24 23:47:05 CET 2018
Dear erlang community,
I’ve been reading the beam book recently, just learned the memory representation of a list is just a con cell which occupy a machine word which 2 bit tag. So It’s make sense that appending a new element on a big list is a small operation. timer:tc/1 shows X = lists:seq(1, 10000) takes 1184us and X2 = [0 | X] only takes 2 us.
But X =:= X1 takes 600us, which shows it walks the whole list to do the equality check, my question is why not just do a cheap con cell immediate comparison since erlang variables don’t vary and tl(X2) points to X1. Is there any method to do the cons equality comparison?
mko_io
More information about the erlang-questions
mailing list