Why does the performance differ so greatly with seemingly the same code?

Does inefficient code cripple the performance of an app?

  • I am not a programming geek, so I could easily foresee writing an app with long lines of code. I was wondering whether there is any difference in performance between smartly-written code and amateur code.

  • Answer:

    It depends on whether your app is performance-sensitive.  For example, code on a web server where multiple people call it simultaneously often needs to be written to be very efficient.  But if it is a client side app, and no one is complaining about performance, then you might be OK. There is a saying, "Premature optimization is the source of all evil".  In other words, first worry about getting your logic so your app works correctly, i.e., gives the right results.  Then if it is too slow, optimize the parts that are slow.

Rob Weir at Quora Visit the source

Was this solution helpful to you?

Other answers

It depends on where the code is. If the code gets called rarely, it is unlikely to cripple an application. If you are calling the code constantly, and it is wasting cycles, it is possible that you may deliver a poor user experience.

Tristan Irwin

I can offer an example from many years ago, when it was easy to measure performance. We had an application that was so badly-written that it gave continuous errors, so I asked a member of the team to rewrite it (if you think it might need re-writing, believe it - it does). The original (batch) program took over four hours to run, and the replacement took 30 minutes - and eliminated the errors from the first program. To an extent, that's the difference between a good programmer and a bad one. The second version wasn't particularly optimised but it was written by an experienced programmer who organised his logic properly.

Doug Scott

Innefficient code is likely to slow an application down, but in truth most applications spend 99% of their time waiting for user input or waiting for data to arrive from the database so the inneficiency of a particular piece of code may never actually be noticed. So it really depends on the number of users/amount of traffic your app will have to cater for. I kind of agree with Rob - people can worry too much about performance too early on, although my counter argument would be that 80% of performance is in the orginal design of the application... so a well designed application with bits of inefficient code is likely to be easier to fix than one that is badly designed. There are some obvious areas where code efficiency is crucial; in embedded systems, for example, developers often measure precisely how many CPU cycles a given function will require, and then agonise about finding smart ways to reduce the number.

Gary Barnett

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.