This discussion is archived
6 Replies Latest reply: May 23, 2013 11:39 AM by EJP RSS

for loop : performance Issue   ???

1008567 Newbie
Currently Being Moderated
Hi all,

Is there any performance issue in bellow code ?

========================

for(int i=0;i<2000;i++){

// code
}


that means if too many records, is there any performance issue with for loop


Thanks..
  • 1. Re: for loop : performance Issue   ???
    jtahlborn Expert
    Currently Being Moderated
    you can't possibly make any meaningful deduction about performance from that snippet of code.

    looking at this and your previous question ( What is the differce in these bellow for loops )... what exactly are you trying to accomplish?
  • 2. Re: for loop : performance Issue   ???
    TPD-Opitz-Consulting-com Expert
    Currently Being Moderated
    1005564 wrote:
    that means if too many records, is there any performance issue with for loop
    even if there was: what do you think will be an alternative?

    bye
    TPD
  • 3. Re: for loop : performance Issue   ???
    939520 Explorer
    Currently Being Moderated
    Be careful that you don't spend all your time looking for minor performance gains when your time can be better spent learning higher level concepts.
  • 4. Re: for loop : performance Issue   ???
    aksarben Journeyer
    Currently Being Moderated
    In most programs, loop performance isn't much of an issue, unless some expensive operation (such as a database query) is inside the loop, and the loop is called many, many times. If everything inside the loop is just done in memory, & doesn't use outside resources, you'll probably be OK.

    Of course, there are exceptions to every rule. If you're doing weather modeling or nuclear explosion simulations, then CPU performance can be an issue. But these are advanced applications, & you're obviously at the beginner level. So for now, don't worry about loop performance unless you have proof that that it's causing a problem.
  • 5. Re: for loop : performance Issue   ???
    morgalr Explorer
    Currently Being Moderated
    Yes, there is:

    But it only exists in your head: it's that notion that you need to have the very tightest possible code instead of plain easily readable source and let the optimizing compiler take it from there. The compiler may not even use your structure that you are trying to optimize, so what's the point?

    Once you have your project, then see if there are any bottlenecks, but in reality, you will be hard pressed to find any significant code changes for opimizaton if you just write good, clean, readable, logically correct code.
  • 6. Re: for loop : performance Issue   ???
    EJP Guru
    Currently Being Moderated
    Is there any performance issue in bellow code ?
    A meaningless question. It depends entirely on what is inside the loop.
    that means if too many records, is there any performance issue with for loop
    Too many records for what? Another meaningless question.

    The loop will execute 2000 times. That is the only thing that can be said about it.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points