I construct two lists, to be used in Pick
as the second argument. The first one is a -1, 1 list and the second one is identical, but with -1 replaced with 0.
n=5*10^6;
a= RandomChoice[{-1,1}, {n}];
b=Unitize[1+a];
Because of the identical structure of both lists, I would have expected that the following timings would give about the same result.
Pick[Range[n], a, 1];// RepeatedTiming
Pick[Range[n],10 a, 10];// RepeatedTiming
Pick[Range[n], b, 1];// RepeatedTiming
Pick[Range[n], 10b, 10];// RepeatedTiming
(*
{0.38,Null}
{0.100,Null}
{0.069,Null}
{0.0780,Null}
*)
They are pretty different. Looking for 1 in the -1, 1 list is almost four times slower than looking for 10 in the corresponding -10, 10 list.
In the following two commands, the arguments of Pick
are identical. Nevertheless, there is a non neglectable difference in the timing:
Pick[Range[n], a+1, 2]; // RepeatedTiming
Pick[Range[n], 2b, 2]; // RepeatedTiming
(*
{0.102,Null}
{0.0773,Null}
*)
What is the reason for these timings being so different?