FACTOID # 155: Australia has more than 28 times the land area of New Zealand, but its coastline is not even twice as long.
 
 Home   Encyclopedia   Statistics   Countries A-Z   Flags   Maps   Education   Forum   FAQ   About 
 
WHAT'S NEW
RECENT ARTICLES
More Recent Articles »
 

FACTS & STATISTICS    Simple view

  1. Select countries to view: (hold down Control key and click to select several)

     

     

    Compare:

     

     

  1. Select fact or statistic: (* = graphable)

     

     

     

  2. (OPTIONAL) Compare to statistic: (both need to be graphable)

     

     

     

  3. View result as:

     

       
(OR) SEARCH ALL encyclopedia, stats & forums:   

Encyclopedia > Optimization (computer science)

In computing, optimization is the process of modifying a system to make some aspect of it work more efficiently or use fewer resources. For instance, a computer program may be optimized so that it executes more rapidly, or is capable of operating within a reduced amount of memory storage, or draws less battery power in a portable computer. The system may be a single computer program, a collection of computers or even an entire network such as the Internet. RAM (Random Access Memory) Look up computing in Wiktionary, the free dictionary. ... A computer program is a collection of instructions that describe a task, or set of tasks, to be carried out by a computer. ... Many different consumer electronic devices can store data. ... Symbols representing a single Cell (top) and Battery (bottom), used in circuit diagrams. ... A Portable computer is a computer that is designed to be moved from one place to another (in other words, it is a computer that is portable). ... A computer program is a collection of instructions that describe a task, or set of tasks, to be carried out by a computer. ... The NASA Columbia Supercomputer. ...


Although the word "optimization" shares the same root as "optimal," it is rare for the process of optimization to produce a truly optimal system. The optimized system will typically only be optimal in one sense or for one audience. One might reduce the amount of time that a program takes to perform some task at the price of making it consume more memory - or in an application where memory space is at a premium, one might deliberately choose a slower algorithm in order to use less memory. There may well be no “one size fits all” design which works well in all cases, so engineers make tradeoffs to optimize the attributes of greatest interest. Additionally, the effort required to make a piece of software completely optimal (ie incapable of any further improvement) is typically more than is reasonable for the benefits that would be accrued; so the process of optimization may be halted before a completely optimal solution has been reached. Fortunately, it is often the case that the greatest improvements come early on in the process. In mathematics, computing, linguistics, and related disciplines, an algorithm is a finite list of well-defined instructions for accomplishing some task that, given an initial state, will terminate in a defined end-state. ... Look up engineer in Wiktionary, the free dictionary. ... A Tradeoff usually refers to losing one quality or aspect of something in return for gaining another quality or aspect. ...


Optimization can occur at a number of levels. 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 the use of efficient algorithms and the coding of these algorithms will benefit from the writing of good quality code. Use of an optimizing compiler can help ensure that the executable program is optimized. At the lowest level, it is possible to bypass the compiler completely and write assembly code by hand. With modern optimizing compilers and the greater complexity of recent CPUs, it takes great skill to write code that is better than the compiler can generate and few projects ever have to resort to this ultimate optimization step. Because optimization often relies on making use of special cases and performing complex trade offs an optimized program can often be more difficult for programmers to comprehend, which can contain in more faults than the unoptimized version. In computer science, efficiency is used to describe several desirable properties of an algorithm or other construct, besides clean design, functionality, etc. ... Compiler optimization techniques are optimization techniques that have been programmed into a compiler. ... An executable or executable file, in computer science, is a file whose contents are meant to be interpreted as a program by a computer. ... Assembly language or simply assembly is a human_readable notation for the machine language that a specific computer architecture uses. ... A software bug is an error, flaw, mistake, failure, or fault in a computer program that prevents it from behaving as intended (e. ...

Contents

Basis

Computational tasks are often performed in several manners with varying efficiency. For example, consider the following C code snippet to sum all integers from 1 to N: C is a general-purpose, block structured, procedural, imperative computer programming language developed in 1972 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system. ...

 int i, sum = 0; for (i = 1; i <= N; i++) sum += i; printf ("sum: %dn", sum); 

This code can (assuming no overflow) be rewritten using a mathematical formula like:

 int sum = (N * (N+1)) / 2; printf ("sum: %dn", sum); 

The optimization, often done automatically, is therefore to pick a method that is more computationally efficient while retaining the same functionality. However, a significant improvement in performance can often be achieved by solving only the actual problem and removing extraneous functionality.


Optimization is not always an obvious or intuitive process. In the example above, the ‘optimized’ version might actually be slower than the original software if N were sufficiently small and the computer were much faster at performing addition and looping operations than multiplications and divisions.


Tradeoff

Optimization will generally focus on improving just one or two aspects of performance: execution time, memory usage, disk space, bandwidth, power consumption or some other resource. This will usually require a tradeoff — where one is optimized at the expense of others. For example, increasing the size of cache improves runtime performance, but also increases the memory consumption. Other common tradeoffs include code clarity and conciseness. A Tradeoff usually refers to losing one quality or aspect of something in return for gaining another quality or aspect. ... Look up cache in Wiktionary, the free dictionary. ...


There are cases where the programmer doing the optimization must decide to make the software more optimal for some operations but at the price of making other operations less efficient. These tradeoffs may often be of a non-technical nature - such as when a competitor has published a benchmark result that must be beaten in order to improve commercial success but perhaps at the price of making normal usage of the software less efficient. Such changes are sometimes jokingly referred to as pessimizations. A benchmark is a point of reference for a measurement. ...


Different fields

In operations research, optimization is the problem of determining the inputs of a function that minimize or maximize its value. Sometimes constraints are imposed on the values that the inputs can take; this problem is known as constrained optimization. It has been suggested that this article or section be merged with Operations management. ...


In computer programming, optimization usually specifically means to modify code and its compilation settings on a given computer architecture to produce more efficient software. Computer programming (often shortened to programming or coding) is the process of writing, testing, and maintaining the source code of computer programs. ... A typical vision of a computer architecture as a series of abstraction layers: hardware, firmware, assembler, kernel, operating system and applications (see also Tanenbaum 79). ...


Typical problems have such a large number of possibilities that a programming organization can only afford a “good enough” solution.


Bottlenecks

Optimization requires finding a bottleneck: the critical part of the code that is the primary consumer of the needed resource. As a rule of thumb, improving 20% of the code is responsible for 80% of the results (see also Pareto principle). A bottleneck is literally the neck of a glass or pottery bottle. ... The Pareto principle (also known as the 80-20 rule, the law of the vital few and the principle of factor sparsity) states that, for many events, 80% of the effects comes from 20% of the causes. ...


The Pareto principle (also known as the 80-20 rule, the law of the vital few and the principle of factor sparsity) states that for many phenomena, 80% of the consequences stem from 20% of the causes. The idea has rule-of-thumb application in many places, but it is commonly misused. For example, it is a misuse to state that a solution to a problem "fits the 80-20 rule" just because it fits 80% of the cases. In computer science, the Pareto principle can be applied to resource optimization by observing that 80% of the resources are typically used by 20% of the operations. In software engineering, it is often a better approximation that 90% of the execution time of a computer program is spent executing 10% of the code (known as the 90/10 law in this context).


The architectural design of a system overwhelmingly affects its performance. The choice of algorithm affects efficiency more than any other item of the design. More complex algorithms and data structures perform well with many items, while simple algorithms are more suitable for small amounts of data — the setup and initialization time of the more complex algorithm can outweigh the benefit. In mathematics, computing, linguistics, and related disciplines, an algorithm is a finite list of well-defined instructions for accomplishing some task that, given an initial state, will terminate in a defined end-state. ...


In some cases, adding more memory can help to make a program run faster. For example, a filtering program will commonly read each line and filter and output that line immediately. This only uses enough memory for one line, but performance is typically poor. Performance can be greatly improved by reading the entire file then writing the filtered result, though this uses much more memory. Caching the result is similarly effective, though also requiring larger memory use.


When to optimize

Optimization can reduce readability and add code that is used only to improve the performance. This may complicate programs or systems, making them harder to maintain and debug. As a result, optimization or performance tuning is often performed at the end of the development stage. Look up readability in Wiktionary, the free dictionary. ... Buskers perform in San Francisco A performance, in performing arts, generally comprises an event in which one group of people (the performer or performers) behave in a particular way for another group of people (the audience). ... Software development stages In computer programming, development stage terminology expresses how the development of a piece of software has progressed and how much further development it may require. ...


Donald Knuth said, paraphrasing Hoare[1], Donald Ervin Knuth ( or Ka-NOOTH[1], Chinese: [2]) (b. ... Sir Charles Antony Richard Hoare (Tony Hoare or C.A.R. Hoare, born January 11, 1934) is a British computer scientist, probably best known for the development of Quicksort, the worlds most widely used sorting algorithm, in 1960. ...

  • "We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil." (Knuth, Donald. Structured Programming with go to Statements, ACM Journal Computing Surveys, Vol 6, No. 4, Dec. 1974. p.268.)

Charles Cook commented, Charles Cook, a relatively common name, encompasses a number of individuals, arranged in chronological order, by year of birth: Charles A. Cook (died after 1863), 19th century American administrator, the first mayor (1861-63) of Denver, Colorado Charles Henry Cook [also known as Chuck Cook] (1926-1993), Canadian radio talk...

  • "I agree with this. It's usually not worth spending a lot of time micro-optimizing code before it's obvious where the performance bottlenecks are. But, conversely, when designing software at a system level, performance issues should always be considered from the beginning. A good software developer will do this automatically, having developed a feel for where performance issues will cause problems. An inexperienced developer will not bother, misguidedly believing that a bit of fine tuning at a later stage will fix any problems." [2]

"Premature optimization" is a phrase used to describe a situation where a programmer lets performance considerations affect the design of a piece of code. This can result in a design that is not as clean as it could have been or code that is incorrect, because the code is complicated by the optimization and the programmer is distracted by optimizing.


An alternative approach is to design first, code from the design and then profile/benchmark the resulting code to see what should be optimized. A simple and elegant design is often easier to optimize at this stage, and profiling may reveal unexpected performance problems that would not have been addressed by premature optimization.


In practice, it is often necessary to keep performance goals in mind when first designing software, but the programmer balances the goals of design and optimization.


Interpreted languages

In interpreted languages (especially those that are executed repeatedly with low latency expectations such as PHP and JavaScript), some programmers remove comments, whitespace, and unused method or function definitions before deploying. PHP is a reflective programming language originally designed for producing dynamic web pages. ... It has been suggested that Client-side JavaScript be merged into this article or section. ... For information on the programming language, see Whitespace programming language. ...


If the programmer discards the original commented and formatted code, maintainability is sacrificed. It becomes harder for a human to read, debug and subsequently modify or extend the code once it has been optimized. In telecommunication, the term maintainability has the following meanings: A characteristic of design and installation, expressed as the probability that an item will be retained in or restored to a specified condition within a given period of time, when the maintenance is performed in accordance with prescribed procedures and resources. ... Debugging is a methodical process of finding and reducing the number of bugs, or defects, in a computer program or a piece of electronic hardware thus making it behave as expected. ...


This anti-pattern can be avoided by keeping a copy of the original code, and by working from the original code when making changes to optimized software. Anti-patterns, comprises the study or specific repeated practices that appear initially to be beneficial, but ultimately result in bad consequences that outweigh the hoped-for advantages. ...


It should also be determined whether removing comments and whitespace really makes a significant difference to the execution time: it's possible that the task of carrying out the "optimization" is significantly greater than the accumulated run time saved. Code such as JavaScript that is transported across a network before being interpreted will benefit from this action to a much greater extent than locally-executed code such as PHP. It has been suggested that Client-side JavaScript be merged into this article or section. ... PHP is a reflective programming language originally designed for producing dynamic web pages. ...


Macros

Optimization during code development using macros takes on different forms in different languages. In high-level languages such as C, macros are implemented using textual substitution, and so their benefit is mostly limited to avoiding function-call overhead. A macro in computer science is an abstraction, that defines how a certain input pattern is replaced by an output pattern according to a defined set of rules. ...


In many functional programming languages, however, macros are implemented using compile-time evaluation and substitution of non-textual, compiled code. Because of this difference, it is possible to perform complex compile-time computations, moving some work out of the resulting program. Lisp originated this style of macro, and such macros are often called “Lisp-like macros.” Functional programming is a programming paradigm that conceives computation as the evaluation of mathematical functions and avoids state and mutable data. ... Lisp is a family of computer programming languages with a long history and a distinctive fully-parenthesized syntax. ...


As with any optimization, however, it is often difficult to predict where such tools will have the most impact before a project is complete.


Automated and manual optimization

Main article: Compiler optimization

See also Category:Compiler optimizations Compiler optimization is the process of tuning the output of a compiler to minimize some attribute (or maximize the efficiency) of an executable program. ...


Optimization can be automated by compilers or performed by programmers. Gains are usually limited for local optimization, and larger for global optimizations. Usually, the most powerful optimization is to find a superior algorithm. Compiler optimization is the process of tuning the output of a compiler to minimize some attribute (or maximize the efficiency) of an executable program. ... In mathematics, computing, linguistics, and related disciplines, an algorithm is a finite list of well-defined instructions for accomplishing some task that, given an initial state, will terminate in a defined end-state. ...


Optimizing a whole system is usually done by human beings because the system is too complex for automated optimizers. In this technique, programmers or system administrators explicitly change code so that the system performs better. Although it can produce better efficiency, it is far more expensive than automated optimizations.


First of all, it is extremely important to use a profiler to find the sections of the program that is taking the most resources - the bottleneck. Programmers usually think they have a clear idea of where the bottleneck is, but intuition is frequently wrong. Optimizing an unimportant piece of code will typically do little to help the overall performance. In computer programming, a profiler is a computer program that can track the performance of another program by checking information collected while the code is executed . ...


When the bottleneck is localized, optimization usually starts with a rethinking of the algorithm used in the program: more often than not, a particular algorithm can be specifically tailored to a particular problem, yielding better performance than a generic algorithm. For example, the task of sorting a huge list of items is usually done with a quicksort routine, which is one of the most efficient generic algorithms. But if some characteristic of the items is exploitable (for example, they are already arranged in some particular order), a different method can be used, or even a custom-made sort routine. Quicksort in action on a list of random numbers. ...


After one is reasonably sure that the best algorithm is selected, code optimization can start: loops can be unrolled (for lower loop overhead, although this can often lead to lower speed, due to overloading the processor's instruction cache), data types as small as possible can be used, integer arithmetic can be used instead of floating-point, and so on. Diagram of a CPU memory cache A CPU cache is a cache used by the central processing unit of a computer to reduce the average time to access memory. ...


Performance bottlenecks can be due to language limitations rather than algorithms or data structures used in the program. Sometimes, a critical part of the program can be re-written in a different programming language that gives more direct access to the underlying machine. For example, it is common for very high-level languages like Python to have modules written in C for greater speed. Programs already written in C can have modules written in assembly. Programs written in D can use the inline assembler. A programming language is an artificial language that can be used to control the behavior of a machine, particularly a computer. ... A high-level programming language is a programming language that, in comparison to low-level programming languages, may be more abstract, easier to use, or more portable across platforms. ... Python is a high-level programming language first released by Guido van Rossum in 1991. ... C is a general-purpose, block structured, procedural, imperative computer programming language developed in 1972 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system. ... See the terminology section, below, regarding inconsistent use of the terms assembly and assembler. ... D is an object-oriented, imperative system programming language designed by Walter Bright of Digital Mars as a re-engineering of C/C++. He has done this by re-designing many C++ features, and borrowing ideas from other programming languages. ... Inline assembler is a feature of programming languages, that enables very low level code written in assembler to be embedded in a high level language like C. This allows programmers to optimise a very performance-sensitive algorithm by sending individual commands to the computers CPU. This example of inline...


Rewriting pays off because of a general rule known as the 90/10 law, which states that 90% of the time is spent in 10% of the code, and only 10% of the time in the remaining 90% of the code. So putting intellectual effort into optimizing just a small part of the program can have a huge effect on the overall speed if the correct part(s) can be located. The 90/10 law is a misstatement of the Pareto Principle. ...


Manual optimization often has the side-effect of undermining readability. Thus code optimizations should be carefully documented and their effect on future development evaluated.


The program that does the automated optimization is called an optimizer. Most optimizers are embedded in compilers and operate during compilation. Optimizers often can tailor the generated code to specific processors.


Today, automated optimizations are almost exclusively limited to compiler optimization. Compiler optimization is the process of tuning the output of a compiler to minimize some attribute (or maximize the efficiency) of an executable program. ...


Some high-level languages (Eiffel, Esterel) optimize their programs by using an intermediate language. Eiffel is an ISO-standardized object-oriented programming language designed for extensibility, reusability, reliability and programmer productivity. ... Esterel is a formally defined synchronous imperative language for the programming of reactive systems. ... In computer science, an intermediate language is the language of an abstract machine designed to aid in the analysis of computer programs. ...


Grid computing or distributed computing aims to optimize the whole system, by moving tasks from computers with high usage to computers with idle time. Grid computing is a phrase in distributed computing which can have several meanings: A local computer cluster which is like a grid because it is composed of multiple nodes. ... Distributed computing is a method of computer processing in which different parts of a program run simultaneously on two or more computers that are communicating with each other over a network. ...


Time taken for optimization

On some occasions, the time taken for optimization in itself may be an issue.


In a software project, optimizing code usually does not add a new feature, and worse, it might break existing functionalities. Because optimized code has lesser readability than a straightforward code, optimization may well hurt the maintainability of the program as well. In short, optimization becomes a cost and it is important to be sure that the investment pays off.


The optimizer (a program that does optimization) may have to be optimized as well. The compilation with the optimizer being turned on usually takes more time, though this is only a problem when the program is significantly large. In particular, for just-in-time compilers the performance of the optimizer is a key in improving execution speed. Usually spending more time can yield better code, but it is also the precious computer time that we want to save; thus in practice tuning the performance requires the trade-off between the time taken for optimization and the reduction in the execution time gained by optimizing code. See also Just in time for the business technique In computing, just-in-time compilation (JIT), also known as dynamic translation, is a technique for improving the performance of interpreted programs. ...


Categories

Code optimization can be broadly categorized as platform dependent and platform independent techniques. Platform independent techniques are generic techniques and are effective for most of digital signal processors (DSP) platforms, such as loop unrolling, reduction in function calls, memory efficient routines, reduction in conditions, etc. Platform dependent techniques involve instruction level parallelism, data level parallelism, cache optimization techniques, i.e. parameters that differ among various platforms.


Quotes

  • “The order in which the operations shall be performed in every particular case is a very interesting and curious question, on which our space does not permit us fully to enter. In almost every computation a great variety of arrangements for the succession of the processes is possible, and various considerations must influence the selection amongst them for the purposes of a Calculating Engine. One essential object is to choose that arrangement which shall tend to reduce to a minimum the time necessary for completing the calculation.” - Ada Byron's notes on the analytical engine 1842.
  • “More computing sins are committed in the name of efficiency (without necessarily achieving it) than for any other single reason - including blind stupidity.” - W.A. Wulf
  • “We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil. Yet we should not pass up our opportunities in that critical 3%.”[1] - Knuth, paraphrasing Hoare
  • “Bottlenecks occur in surprising places, so don't try to second guess and put in a speed hack until you have proven that's where the bottleneck is.” - Rob Pike
  • “The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson

In 1840 Charles Babbage was invited to give a seminar at the University of Turin about his analytical engine. ... Donald Knuth Donald Ervin Knuth (born January 10, 1938) is a renowned computer scientist and Professor Emeritus at Stanford University. ... Sir Charles Antony Richard Hoare (Tony Hoare or C.A.R. Hoare, born January 11, 1934) is a British computer scientist, probably best known for the development of Quicksort, the worlds most widely used sorting algorithm, in 1960. ... Rob Pike (born 1956) is a software engineer and author. ... Professor Michael Anthony Jackson (born 1936) works as an independent computing consultant in London, England, and also as a part-time researcher at AT&T Research, Florham Park, NJ, USA. He is a visiting research professor at the Open University in the UK. Jackson was educated at Harrow School where...

See also

Compiler optimization is the process of tuning the output of a compiler to minimize some attribute (or maximize the efficiency) of an executable program. ... In computer science, abstract interpretation is a theory of sound approximation of the semantics of computer programs, based on monotonic functions over ordered sets, especially lattices. ... This article is about the computer term. ... A control flow graph (CFG) is a representation, using graph notation, of all paths that might be traversed through a program during its execution. ... In computer programming, lazy evaluation is a technique that attempts to delay computation of expressions until the results of the computation are known to be needed. ... Most execution time of a scientific program is spent on loops. ... Low Level Virtual Machine, generally known as LLVM, is a compiler infrastructure designed for compile-time, link-time, run-time, and idle-time optimization of programs written in arbitrary programming languages. ... Memoization is a technique used to speed up computer programs by storing the results of functions for later reuse, rather than recomputing them. ... Memory Locality is a term in computer science used to denote the temporal or spatial proximity of memory access. ... In software engineering, performance analysis (a field of dynamic program analysis) is the investigation of a programs behavior using information gathered as the program runs, as opposed to static code analysis. ... Queueing theory (also commonly spelled queuing theory) is the mathematical study of waiting lines (or queues). ... Look up simulation in Wiktionary, the free dictionary. ... In computer science, speculative execution is the execution of code whose result may not actually be needed. ... In compilers, static single assignment form, more often abbreviated SSA form or just SSA, is an intermediate representation in which every variable is assigned exactly once. ... The worst-case execution time (WCET) of a computational task is the maximum time span a task may execute on a specific hardware platform. ...

References

  1. ^ Knuth, Donald: Structured Programming with Goto Statements. Computing Surveys 6:4 (1974), 261–301.

Donald Ervin Knuth ( or Ka-NOOTH[1], Chinese: [2]) (b. ... Jon Louis Bentley (?–?) is a researcher in the field of computer science. ... Donald Ervin Knuth ( or Ka-NOOTH[1], Chinese: [2]) (b. ... Cover of books The Art of Computer Programming[1] is a comprehensive monograph written by Donald Knuth which covers many kinds of programming algorithms and their analysis. ...

External links


  Results from FactBites:
 
Encyclopedia4U - Optimization (computer science) - Encyclopedia Article (3316 words)
In operations research, optimization is the problem of determining the inputs of a function that minimize or maximize its value.
Because of that, it is preferable that optimization or performance tuning is done in the end of development stage.
Optimizing a whole system is usually done by human beings because the system is too complex for automated optimizers.
  More results at FactBites »


 

COMMENTARY     


Share your thoughts, questions and commentary here
Your name
Your comments
Please enter the 5-letter protection code

Want to know more?
Search encyclopedia, statistics and forums:

 


Lesson Plans | Student Area | Student FAQ | Reviews | Press Releases |  Feeds | Contact
The Wikipedia article included on this page is licensed under the GFDL.
Images may be subject to relevant owners' copyright.
All other elements are (c) copyright NationMaster.com 2003-5. All Rights Reserved.
Usage implies agreement with terms.