conditions and `for` iterations

K K <pmi.imp@gmail.com>
Fri, 27 Feb 2009 09:23:55 +0100

          From comp.compilers

Related articles
conditions and `for` iterations pmi.imp@gmail.com (K K) (2009-02-27)
Re: conditions and `for` iterations cfc@shell01.TheWorld.com (Chris F Clark) (2009-02-27)
Re: conditions and `for` iterations petit@xmail.net (2009-03-07)
Re: conditions and `for` iterations cfc@shell01.TheWorld.com (Chris F Clark) (2009-03-11)
| List of all articles for this month |

From: K K <pmi.imp@gmail.com>
Newsgroups: comp.compilers
Date: Fri, 27 Feb 2009 09:23:55 +0100
Organization: Compilers Central
Keywords: code, question
Posted-Date: 27 Feb 2009 07:33:32 EST

Hello all,


I'm new to compilers and just to quench my own curiosity I was
wondering on the following:


Regarding languages C++ and Java, is there a performance difference
between the following pseudo code snips regarding the effects of:


* the taken/not taken conditions and the CPU/JVM branch prediction;
* and/or pipeline invalidations on missed branches;


And if there's no performance difference, which version would you
choose (regarding maintainability, etc.)?


----


for (int i=0; i < array_len; i++ )
{
    if ( array[i] == requested_item )
    {
          found = true;
          break;
    } // if


} // for


if found ....
----


for (int i=0; i < array_len; i++ )
{
    if ( array[i] != requested_item )
    {
          continue;
    } // if


    found = true;
    break;
} // for


if found ....
----


Thanks for your time,


Karoly
[I would expect that a decent optimizer would untangle the control flow
and generate similar code for either. -John]



Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.