Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re: does perl have branch prediction

by oiskuu (Friar)
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

Comment on Re: does perl have branch prediction
Select or Download Code

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 making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2015-11-28 13:09 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (741 votes), past polls