Here are two bulky yet fast compiled functions. The two functions are essentially the same, but the second one is slightly adapted to rashers test case for timing comparisons. In my previous version they were even longer, but it turns out they are faster this way.
cfu =
Compile[
{{ints, _Integer, 1}}
,
Block[
{len, zFlag, res}
,
res = True;
len = Length@ints;
zFlag = False;
Do[
If[
ints[[i]] == 0
,
zFlag = True;
,
If[
zFlag
,
res = False;
Break[]
]
];
,
{i, 1, len}
];
res
]
,
CompilationTarget -> "C"
]
cfu2 =
Compile[
{{int2s, _Integer, 2}}
,
Block[
{len, bigLen, zFlag, res, ints}
,
bigLen = Length@int2s;
Table[
ints = int2s[[jj]];
res = 1;
len = Length@ints;
zFlag = False;
res = True;
len = Length@ints;
zFlag = False;
Do[
If[
ints[[i]] == 0
,
zFlag = True;
,
If[
zFlag
,
res = False;
Break[]
]
];
,
{i, 1, len}
];
res
,
{jj, 1, bigLen}
]
]
,
CompilationTarget -> "C"
]
We then have
Column[{fx2r = fx2[test]; // Timing // First,
ww = fx[test]; // Timing // First,
xx = ! MatchQ[#, p1] & /@ test; // Timing // First,
test5 = OrderedQ@Reverse@Unitize@# & /@ test; // Timing // First,
f1r = f1 /@ test; // Timing // First,
f2r = f2 /@ test; // Timing //
First, (jRes = cfu /@ test) // Timing //
First, (jRes2 = (# != 0) & /@ cfu2@test) // Timing // First,
ww == xx == test5 == f1r == f2r == fx2r == jRes == jRes2}
]
0.112896
0.212937
0.656224
0.256140
0.812663
1.000797
0.105754
0.059129
True
Note: The timing can be made slightly faster by manually compiling (# != 0) &
.