Questions tagged [optimization]

Optimization is the process of improving an existing program to make it work more efficiently or/and using less resources.

Since optimization may occur at various stages (analysis, design, implementation, compiler, runtime, etc.) during the development of a program, and according to the FAQ, the following types of questions are certainly valid:

  • What is/is it considered optimization, with a detailed question about what you are referring to (remember that "programmers" is not "code review"). Theoretical questions on algorithms efficiency are OK.
  • What can(not) be optimized given a context (for example #1 or #2).

Beware that some more "general" questions about optimization have already been asked. Most notably "when to perform optimization", "when to stop optimizing", "is premature optimization really bad"...

More information on optimization may be found on Wikipedia: Optimization.

400 questions
82
votes
14 answers

When is optimization not premature and therefore not evil?

"Premature optimization is root of all evil" is something almost all of us have heard/read. What I am curious what kind of optimization not premature, i.e. at every stage of software development (high level design, detailed design, high level…
Gaurav
  • 3,729
  • 2
  • 26
  • 43
41
votes
6 answers

How does branch prediction work, if you still have to check for the conditions?

I was reading the popular answer about Branch Prediction from https://stackoverflow.com/q/11227809/555690, and there is something confusing me: If you guessed right, it continues on. If you guessed wrong, the captain will stop, back up, and yell…
Saturn
  • 3,907
9
votes
4 answers

Am I prematurely optimizing?

I'm currently at the design stage of a component-based architecture in C++. My current design includes the usage of features such as: std::vectors of std::shared_ptrs to hold the…
Vaillancourt
  • 203
  • 1
  • 8
8
votes
8 answers

Is premature optimization always bad?

I work in a small sized software/web development company. I have gotten into the habit of optimizing prematurely, I know it is evil and promotes bad code, but I have been working at this firm for a long while and I have deemed this as a necessary…
MattyD
  • 2,295
  • 1
  • 17
  • 18
8
votes
2 answers

How big sites scale up and optimize to massive traffic?

How do sites like Facebook and Twitter optimize their sites for massive traffic. Aside from spending big bucks on getting the best servers, what can be optimized in your code to accommodate massive traffic? I've read about caching your pages to…
user9811
2
votes
2 answers

Calculating NPath Complexity

I'm trying to calculate the NPath Complexity within a function, but I'm unsure what parts I count. My understanding is that it'll sum: If Else Else If Switch Case Default Do While Is this correct? Or am I missing something?
James
  • 121
1
vote
1 answer

Optimizing programs by identifying and taking evaluation (calculation) shortcuts

Recently I am working on a project that involves a lot of simple numerical calculations being applied to large arrays. The numerical values are very simple but there are many different types, such as positive integers, negative integers, small…
rwong
  • 16,878
1
vote
1 answer

The optimal way to reschedule appointments

Let's say I have the following appointments: Appointment 1 = 1:00 Appointment 2 = 2:00 Appointment 3 = 3:00 Appointment 4 = 4:00 I need to reschedule all of these one hour later: Appointment 1 = 2:00 Appointment 2 = 3:00 Appointment 3 =…
Mohair
  • 383
1
vote
1 answer

Optimization of time-varying parameters

I need to find an optimal set of "n" parameter values that minimize an objective function (a 2-hr simulation of a system). I have looked at genetic algorithm and simulated annealing methods, but was wondering if there are any better algorithms and…
brama
  • 111
1
vote
4 answers

Write then optimise or write optimised

Do you write your code then optimise it? Or do you write an optimised code from the beginning. I always believe in writing optimised since I really dont like to rewrite code, But please share your thoughts.
saadlulu
  • 121
  • 5
0
votes
0 answers

Efficient way/query to find related entities

Let's say we have following SQL table structure Entities (5-15k) Keywords (15-20k) EntityKeywords ExcludedKeywords (keywords which should be excluded from common matching) We need to find related entities, which are entities which have most common…
Robert
  • 545
0
votes
1 answer

Approaching Particle Swarm Optimization with optimization problem, how to use PSO with it?

I am learning Particle Swarm Optimization. The problem is to find the pair of number whose sum is lowest. Lets say we have some numbers z1,z2,z3,z4 Number Value z1 -2 z2 -3 z3 3 z4 -5 The goal is to find pairs of number whose…
0
votes
1 answer

Optimization: How much time saved is considered worth it?

I was reading up about branch predictions and cache misses, and have decided to read what every programmer should know about memory. But I'm not sure how much low level knowledge do I need to have to write performant code. One classic example is…
-1
votes
1 answer

how to model this relation by linear constraints?

v = |x1-x2| with 0<=xj<=C for j=1,2, C constant I was trying to moel this relation by linear constraints. This is what I've done equality is equivalente to superior and inferior relation. begining with v>=|x1-x2| : this "superior" relation can be…
Ayman
  • 1
-2
votes
1 answer

Server-side vs. Client-side markup - whichi is more efficient?

The background of this question is stemming from an article about someone who operates a website that is powered by a solar panel and the carbon footprint that we produce in the software space. Data centers use around 2% of the world's energy. It's…
1
2