Questions tagged [micro-optimization]

Micro-optimization is the process of meticulous tuning of small sections of code in order to address a perceived deficiency in some aspect of its operation (excessive memory usage, poor performance, etc).

Micro-optimization is the process of meticulous tuning of small sections of code in order to address a perceived deficiency in some aspect of its operation (excessive memory usage, poor performance, etc).

Micro-optimization (and optimization in general) tends to be interesting to programmers because they enjoy finding clever solutions to problems. However, micro-optimization carries the connotation of a disproportionate amount of effort being expended to extract relatively small improvements.

That's not to say that micro-optimization is bad practice in all circumstances. Sometimes a small improvement in a part of a code base that gets used frequently (such as the innermost part of a loop) can yield big overall gains in system performance, and building code for highly constrained systems such as microcontrollers will often require cleverness to eke out the most performance from such a small system.

However, it can be tempting to indulge in the practice where it's not necessary, resulting in a lot of time being spent that could have been used more productively, and in code that is difficult to follow as "clever" solutions to problems are often more difficult to understand than simple solutions, and therefore a micro-optimization can have a negative impact on the maintainability of a piece of code.

Programmers are advised to avoid micro-optimization, unless they can make a solid justification for the problems outlined above being worth the performance gains. Should profiling of the code in question identify a hot-spot that is causing a performance bottleneck, then this can be sufficient justification for a micro-optimization.

900 questions
0
votes
2 answers

Want to understand load imputed by floating point instructions

At outset, this may be a part-discussion part-solving kind of questions. No intent to offend anyone there. I have written in 64 bit assembly the algorithm to generate MT Prime based random number generator for 64 bits. This generator function is…
quasar66
  • 555
  • 4
  • 14
0
votes
1 answer

JIT Optimization of an indexer which is only modified sequentaly

I am curious as to what happens in this situation: int i = 0; MessageBox.Show(i++.ToString ()); MessageBox.Show(i++.ToString ()); Array[i++] = Foo; Assuming this is the only way i is used in the method,does the JIT strip out i and replace it with…
user164771
0
votes
3 answers

CSS micro-optimization

I'm considering micro-optimization of a huge CSS stylesheet and have a couple questions related to that: Is lowercase better than uppercase for reducing file size? Is background-position:right (5 chars); smaller than background-position:0 100%; (6…
eozzy
  • 66,048
  • 104
  • 272
  • 428
0
votes
1 answer

Can reading the dataset be faster in time and/or better in memory than this?

In Java, here is the code to read a file with a table of integers: public static int[][] getDataset() { // open data file to read n and m size parameters BufferedReader br = null; try { br = new BufferedReader(new…
Sophie Sperner
  • 4,428
  • 8
  • 35
  • 55
0
votes
2 answers

Fast way to scan a double - c++

I'm trying to optimize my solution to a problem, which requires fast double scanning. I tried to implement a function which read a double from the standard input, but I failed. Could someone point me some simple code which implements this…
Rontogiannis Aristofanis
  • 8,883
  • 8
  • 41
  • 58
0
votes
3 answers

Optimizing Java code

How can I optimize this code ? I made IPFilter and I need to optimize it. package com.ipfilter; import java.util.HashMap; import java.util.Map; /** * IPFilter * * Loads given IP addresses to memory, so you can easily check if ip…
newbie
  • 24,286
  • 80
  • 201
  • 301
0
votes
3 answers

JavaScript: Is the `if / else` statement faster than the conditional statement in?

Consider the following two pieces of code: var adj=0>grip.y?0 0) adj = 0; else adj = -180; } else { if (grip.x > 0) adj =…
0
votes
1 answer

Delete from multiple tables with common column in one query?

Micro optimization I know, this is more because I am curious. I have two link tables, blog_categories_posts => post_id, category_id blog_tags_posts => post_id, tag_id I am removing all links from both tables based on the post_id: DELETE…
Hailwood
  • 89,623
  • 107
  • 270
  • 423
0
votes
3 answers

Micro optimization - compiler optimization when accesing recursive members

I'm interested in writing good code from the beginning instead of optimizing the code later. Sorry for not providing benchmark I don't have a working scenario at the moment. Thanks for your attention! What are the performance gains of using…
Marcus Frenkel
  • 691
  • 10
  • 19
0
votes
7 answers

PHP Function execution cost table

There is a reference table that shows the execution cost of every php function? I know that the time execution is boundet to many factors and is impossible to determinate an unique value, but im looking for a 'ideological' table. For…
Strae
  • 18,807
  • 29
  • 92
  • 131
0
votes
3 answers

Keeping a counter variable vs using count() at every iteration in PHP

In an infinite loop, i want to break out based on number of elements in an array. Say: $myarr = array(); While (True){ //... do something that modifies $myarr ... if (count($myarr) > 100000) { break; } } The problem is, every time i try to…
Titon
  • 139
  • 2
  • 7
0
votes
2 answers

Performance optimization multipliers

Can anyone provide an example of a system in which a performance improvement of x% to a single sub-component of the system results in an overall performance increase of Ax% (where A>1) for the entire system? In other words, can there be a positive…
Dan Hermann
  • 1,107
  • 1
  • 13
  • 27
0
votes
2 answers

Is this code ineffective/slow?

Possible Duplicate: How is an array in a PHP foreach loop read? If I have this function: function getList() { $list = array(); $list['foo'] = 'Foo'; $list['bar'] = 'Bar'; return $list; } And then I do this: foreach ( getList() as…
Ali
  • 261,656
  • 265
  • 575
  • 769
-1
votes
3 answers

Optimising this function

I have a script which calls this function more than 100k times, so I am looking for anyway to squeeze a bit more performance out of it. Can you suggest optimisations or an alternate method for calculating standard deviation in PHP? function…
Andrew Hall
  • 3,058
  • 21
  • 30
-1
votes
4 answers

Implement an if/else condition in x86 assembly that selects one of two constants (that differ by 1)

Can someone help me translate this pseudocode into x86 assembly? if (eax > ebx) mov dl, 5; else mov dl, 6;
TonsOfDamage
  • 19
  • 1
  • 1
  • 6