In reply to Ian Wakeling.

Yes, it is an interesting graph! If you time the LOC function by itself, it looks like the graph of the REMOVE function: it goes up, reaches a peak at prob=0.5, then goes down. As you say, if you time the subscript operation by itself, it increases linearly. Consequently, the superposition flattens out, as you see.

As to why the LOC function requires LESS time when it returns a LONGER vector, my conjecture is that it is because of the way that computer cache works. Even though the function has to copy MORE values, it is cheap to copy a value that is already in the cache. For long vectors, it is very probable that observation (i+1) is in the cache, given that observation i is in the cache. So the LOC function experiences fewer cache misses in this case.

Does anyone have a competing theory? If so, post your ideas.