Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: does perl have branch prediction

by oiskuu (Pilgrim)
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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (7)
As of 2014-07-30 12:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (231 votes), past polls