3 ms·
Can someone help me understand the following statement (specifically the don't branch part) ? "Don’t touch the kernel. Don’t touch main memory … Don’t branch.’
by guiomie 12y ago
Can someone help me understand the following statement (specifically the don't branch part) ?
"Don’t touch the kernel. Don’t touch main memory … Don’t branch.’ (That third commandment means don’t fill your program with ‘if’ statements – ones with the generic form ‘if A then do B else do C’ – because they get in the way of a modern microprocessor’s capacity to do several things in parallel.)"
- kasey_junk 12y agoIt is probably referring to the fact that code that branches allot will make the prefetcher/branch predictor fail more frequently which causes slower memory loads and less ops. Not sure why it mentions parallelism though.
- bluecalm 12y agoObligatory link: http://stackoverflow.com/questions/11227809/why-is-processing-a-sorted-array-faster-than-an-unsorted-array http://stackoverflow.com/questions/11227809/why-is-processin... see most upvoted answer for short lecture about cost of branching in modern CPU's.