Start networking and exchanging professional insights

Register now or log in to join your professional community.

Follow

What is code optimization in programming?

user-image
Question added by Shagufta Mubasher , Web Developer , MP CJ O Shopping Sdn. Bhd.
Date Posted: 2014/07/17
Ayushi Bansal
by Ayushi Bansal , Intern , Wipro Infotech Ltd.

Code Optimization refers to an efficient working of the programming. And efficient is in terms of time and space complexity of the program. 

Thanks for inviting

The code optimization is the process of modifying asystem to make some aspect of it work more efficiently or use fewer resources.

Muhammad Majid Saleem
by Muhammad Majid Saleem , Senior PHP Developer / Project Manager , SwaamTech

Code optimization is a set of methods of code modification to improve code quality and efficiency. A program may be optimized so that it becomes of a smaller size, consumes less memory, executes more rapidly, or performs fewer input/output operations.

 

Read full story: http://www.viva64.com/en/t/0084/

Muhammad Ahmed Raza
by Muhammad Ahmed Raza , Web Developer & Technical Support Head , Ninja Softs (Private) Limited

Shorter and Logical in code, but better in performance.

Bishal Gnyawali
by Bishal Gnyawali , Product Manager , Wserve

code optimization is the process of making code more efficient in Time and Space complexity context.

That means reducing code for faster execution, and also making the code executable with few memory (ram)and harddisk resources.

for example avoid recursion as much as possible in the code, which will automatically reduce the space complexity because recursion is implemented in a stack.

use function to find the solution in one step.

for eg. like for sum of integers use n(n+1)/2

rather than for//while loop to calculate the sum of integers till n.

1+2+3+.....+n

this will reduce time complexity

 

Program optimization or software optimization is the process of modifying a software system to make some aspect of it work more efficiently or use fewer resources. In general, a computer program may be optimized so that it executes more rapidly, or is capable of operating with less memory storage or other resources, or draw less power.

 In it’s most basic form, it means don’t try and figure something out the hard way if you don’t have to. In terms of how a computer works, everything you tell it to do requires Resources ( for the most part this will be Memory / RAM ) and  processing power ( The computer’s processor and usually the graphics card’s processor too ). Usually, the more complicated / long-winded your code is, the more resources and processing power it will take for the computer to complete.

 Let’s say someone asked you how often you went to visit your family every week. And for the sake of argument let’s say you went every Monday and Wednesday…Most people will probably figure it out like this inside their head:

“I know there are7 days in the week, Monday and Wednesday are2 of those days .. So therefore I go twice a week. The answer is2.”

If this was programmed, it could be expressed like this:   (7 /7 ) *2 =2;

A longwinded (and very silly) way of figuring this out would be like this:

“I know there are365 days in a year, and that is equal to around52 weeks, of those52 weeks I go every Monday and Wednesday, so that makes it104 when I multiply those together .. So if I divide the number of visits I made every year by the number of weeks in a year, that makes it2.”

In programming, that thought process would look like this:

numberOfWeeksInYear = Round(365 /7 );      (equals52)

numberOfVisits = numberOfWeeksInYear *2;    (equals104 )

numberOfVisits / numberOfWeeksInYear =2;

Technically, both methods are correct because they arrived at the same answer. But It’s pretty clear the first method was going to take far less time for you to figure out, which allowed you to move on with your life and go get a milkshake or something!

In Code Optimization the same idea applies, the faster the computer can figure something out, the faster it can move onto something else.

source

Cheers!

 

Jaya Parwani
by Jaya Parwani , Sr Software Consultant , Oracle - India

In practical Programming point of view Code optimization means coding in such a manner that makes it less complex in the contxt of time & space complexity. It can be optimized to execute much rapidly, or use fewer resources like OS time (machiene cycles & instruction cycles), power, memory (less rapid pagination) etc

Optimization can be achieved till various levels of Depth: 

1. Algorithm Design

2. Line of Code Reducing

3. Compile time reducing (destroying variables after use)

4. Avoiding re-writing of same code for different classes & functions (make common functions)

5. Runtime (use of Stack recursion, Database Query Call/Execution within loops, Using INNER Joins in one-to-many or many-to-many relations)

6. Logical Level (Creation & normalization of Database) 

Ofcourse at the Database Design level professionally you can ignore space complexity upon time complexity but you have to manage it accordingly which one is primely needed, so the course of action will be according to your need

 

Moaiad Hawash
by Moaiad Hawash , Senior .Net Developer and Project System Analyst , Trainera

Optimization is a very broad and simple term. In general it implies modifying the system to make some of its aspect to work more efficiently or use fewer resources or be more robust.

For example, a computer program may be optimized so that it will execute faster or use less memory or disk storage or be more responsive in terms of UI.

 

Although "optimization" has the same root as "optimal", the process of optimization does not produce a totally optimal system: there's always a trade-off, so only attributes of greatest interest are optimized.

 

Optimization mainly have2 levels:

Design level

At the highest level, the design may be optimized to make best use of the available resources. The implementation of this design will benefit from a good choice of efficient algorithms and the implementation of these algorithms will benefit from writing good quality code. The architectural design of a system overwhelmingly affects its performance. The choice of algorithm affects efficiency more than any other item of the design. In some cases, however, optimization relies on using fancier algorithms, making use of special cases and special tricks and performing complex trade-offs; thus, a fully optimized program can sometimes, if insufficiently commented, be more difficult for less experienced programmers to comprehend and hence may contain more faults than unoptimized versions.

Source code level

Avoiding bad quality coding can also improve performance, by avoiding obvious slowdowns. After that, however, some optimizations are possible which actually decrease maintainability; some, but not all of them can nowadays be performed by optimizing compilers. For instance, using more indirection is often needed to simplify or improve a software, but that indirection has a cost.

Prabakaran krishnan
by Prabakaran krishnan , Senior Consutant , CSC Technologies Ltd

Main intention of optimization is improve the perfrmance of code. For example removing the unneeded stuffs like unneeded variable decarations, making unused objects null.

Andri Darmawan
by Andri Darmawan , IT Manager , PT Tolan Tiga Indonesia

code optimization in simple explanation is :  "better result with simpler way" :-)

GEORGE EID
by GEORGE EID , FINANCE MANAGER , SLEEMAN BREWERIES LIMITED

Code optimization is the process in which a code is modified to remove unused operations or order operations in systematic method that increases the speed of completion, reduces the memory required to complete the code, reduces the storage space required to save it and returns only necessary information.   

More Questions Like This

Do you need help in adding the right keywords to your CV? Let our CV writing experts help you.