n = 2 10^6;
a = RandomReal[{0, 1}, {n}];
k = UnitStep[# - n/4 - 1]~BitAnd~UnitStep[3 n/4 - #] &@Range[n];
k2 = With[{n = n}, Compile[x, n/4 + 1 <= x <= 3 n/4 // Not // Boole,
RuntimeAttributes -> Listable]]@Range[n];
r1 = (2 a + 3) BitXor[k, 1] // Hash // AbsoluteTiming
r2 = (2 a + 3) k2 // Hash // AbsoluteTiming
{0.232013, 1123183045}
{0.189011, 1123183045}
n = 100;
b = RandomReal[{0, 1}, {n, n, n}];
Table[If[i^2 + j^2 + k^2 <= n^2, 0., 2 b[[i, j, k]] + 3],
{i, n}, {j, n}, {k, n}] // Hash // AbsoluteTiming
cf =With[With[{n = n, i = A[[1]], j = A[[2]], kb = A[[3]]b},
Compile[{{A, _Real, 1}},
i^2Table[If[i^2 + j^2 + k^2 <= n^2 // Not //, Boole0.,
2 b[[i, j, k]] RuntimeAttributes+ ->3], Listable
]] // Quiet;
(
k = cf@Outer[List{i, #n}, #{j, #] &@Range[n];
(2 b + 3)n}, {k, n}]]][] // Hash
) // AbsoluteTiming
(
k2 = With[{n = n},
Table[UnitStep[n^2 - (i^2 + j^2 + k^2)], {i, n}, {j, n}, {k, n}]];
(2 b + 3) BitXor[k2, 1] // Hash
) // AbsoluteTiming
(
k3 = With[{n = n, k = Range@n},
Table[UnitStep[n^2 - (i^2 + j^2 + k^2)], {i, n}, {j, n}]];
(2 b + 3) BitXor[k3, 1] // Hash
) // AbsoluteTiming
{6.528373, 92915038}
{0.344020359021, 92915038985443966}
{0.282016294017, 92915038985443966}
{0.169010, 92915038985443966}