in reply to does perl have branch prediction

Note that CPUs (these days) support conditional instructions; good compilers make use of these. Loop body such as

if (v[i] >= 128) sum += v[i];
is likely compiled with a cmov on x86/x86_64 and therefore incurs no branch misprediction penalty.

As for the perl version: the effects of misprediction are practically negligible, lost in the noise.

perf stat perl5.18.1 -e '@a = map {($i += 1.1e-0) + rand} 1..3e6; $i = + $i/2 + 0.5; $_ > $i and $n+=$_ for @a;' 8509781489 instructions 1701278883 branches 3938702 branch-misses 1.561091272 seconds time elapsed perf stat perl5.18.1 -e '@a = map {($i += 1.1e-10) + rand} 1..3e6; $i += $i/2 + 0.5; $_ > $i and $n+=$_ for @a;' 8505802267 instructions 1700634854 branches 5437641 branch-misses 1.567880931 seconds time elapsed