S
s
Hello all,
I was wondering on the following:
Regarding modern C++ compilers, is there a performance difference
between the following pseudo
code snips regarding the effects of:
* the taken/not taken conditions/branches and the CPU branch
prediction;
* and/or pipeline invalidations on missed branches;
And if there's no performance difference, which version would you
choose (regarding maintainability,etc.)?
## version 1 with `break`
for (int i=0; i < array_len; i++ )
{
if ( array == requested_item )
{
found = true;
break;
} // if
} // for
if found ....
## version 2 with `continue`
for (int i=0; i < array_len; i++ )
{
if ( array != requested_item )
{
continue;
} // if
found = true;
break;
} // for
if found ....
I was wondering on the following:
Regarding modern C++ compilers, is there a performance difference
between the following pseudo
code snips regarding the effects of:
* the taken/not taken conditions/branches and the CPU branch
prediction;
* and/or pipeline invalidations on missed branches;
And if there's no performance difference, which version would you
choose (regarding maintainability,etc.)?
## version 1 with `break`
for (int i=0; i < array_len; i++ )
{
if ( array == requested_item )
{
found = true;
break;
} // if
} // for
if found ....
## version 2 with `continue`
for (int i=0; i < array_len; i++ )
{
if ( array != requested_item )
{
continue;
} // if
found = true;
break;
} // for
if found ....