I would like to understand the implementation that allows MemberQ
and FreeQ
to be as fast as they are.
I noticed this thanks to this fine answer.
I start with a list of True|False values:
lst = Insert[Table[True, {500000}], False, 499000];
It is not packed:
Developer`PackedArrayQ[lst]
False
I compare timings:
Scan[Identity, lst] ~Do~ {100} // Timing
MemberQ[lst, False] ~Do~ {100} // Timing
FreeQ[lst, False] ~Do~ {100} // Timing
{4.93, Null}
{0.405, Null}
{0.25, Null}
What allows these functions to be more than an order of magnitude faster than simply Scanning the list?