Branch prediction is an optimization technique which predicts the path a code will take before it is known for sure. This matters because while executing a code, the machine loads the few code statements in advance and keeps it in the pipeline. The problem occurs when there is a conditional branch in which case, there are two possible paths or code section that can be executed.
Read this article to understand branch prediction with a code example
The code example in the article demonstrates how a failure to predict the branch results in two times slower execution. This is a must read as this will give further insights into how to optimize code execution.
Have a doubt or thought? Join the discussion now
This is a companion discussion topic for the original entry at http://iq.opengenus.org/branch-prediction-explained-with-a-code-example/