Cause of speed up
This is definitely not a memoization. The reason for thethis speed up is that when you work with veryfor large arrays (like 10^8 elements), the memory clean up operations may take significant time. If you don't cleanone doesn't free memory you, one can save some time.
Here is an example:
Let's create a large array, perform a calculation, and remove the array:
AbsoluteTiming[ Total[ConstantArray[0, 10^8]]; ]
{0.422509, Null}
Let's now do the same thing, but keep the array in memory:
AbsoluteTiming[ Total[garbage = ConstantArray[0, 10^8]]; ]
{0.366755, Null}
ItThis evaluation is noticably faster.
Let's check how long does it take to remove athe large array:
AbsoluteTiming[ Remove[garbage] ]
{0.061982, Null}
ItNote that, it is the difference of the calculation times above.
[Edit: as noted by Carl Woll in comments, if one wants to makemeasure symbol-removing-time this experiment correctlyway:
garbage = ConstantArray[0, 10^8]; AbsoluteTiming[Remove[garbage]]
one should set $HistoryLength to zero, otherwise an Out[] variable canwill retain the contents of large array garbage. In this case Clear[]Remove[garbage] will instantly delete the reference, but not actually clean the memory and will be executed instantlylarge data itself. ]End of edit]
Your example
In the example you provide, removing the result of Unitize@data[[All, n]] array from memory takes significant time. If one saves this array in a redundant variable, one avoids memory clean-up and wins some time.
How to make testa representative test?
You should put Clear[pick, unitize] inside your timing function. This will show that the pseudo-memoization technique is actually slower than built-in functions:
Table[ Clear[data]; data=RandomInteger[{0,10},{i*10^7,3}]; { Pick[data,Unitize@data[[All,-1]],1]; // AbsoluteTiming // First , Clear[pick,unitize]; unitize[x_]:=unitize[x]=Unitize[x]; pick[xs_,sel_,patt_]:=pick[xs,sel,patt]=Pick[xs,sel,patt]; pick[data,unitize@data[[All,-1]],1]; // AbsoluteTiming // First }, {i,5}] (* {{0.534744, 0.469538}, {1.03776, 1.05842}, {1.58536, 1.65404}, {2.10422, 2.11284}, {2.48129, 2.71405}} *)