Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re: does perl have branch prediction

by oiskuu (Hermit)
on Jan 29, 2014 at 12:24 UTC ( #1072499=note: print w/replies, xml ) Need Help??

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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1072499]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (10)
As of 2016-10-24 21:18 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (310 votes). Check out past polls.