For questions pertaining to the measurement or improvement of code efficiency.

learn more… | top users | synonyms (18)

4599
votes
11answers
238k views

Why is processing a sorted array faster than an unsorted array?

Here is a piece of C++ code that shows some very peculiar performance. For some strange reason, sorting the data miraculously speeds up the code by almost 6x: #include <algorithm> #include ...
750
votes
45answers
263k views

Slow Android emulator

I have a 2.67 GHz Celeron processor, 1.21 GB of RAM on a x86 Windows XP Professional machine. My understanding is that the Android emulator should start fairly quickly on such a machine, but ...
716
votes
10answers
113k views

Why is one loop so much slower than two loops?

Suppose a1, b1, c1, and d1 point to heap memory and my numerical code has the following core loop. const int n=100000 for(int j=0;j<n;j++){ a1[j] += b1[j]; c1[j] += d1[j]; } This loop ...
636
votes
3answers
73k views

Why does changing 0.1f to 0 slow down performance by 10x?

Why does this bit of code, const float x[16] = { 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6}; const float ...
555
votes
14answers
47k views

Is < faster than <=? [closed]

I'm reading a book where the author says that if( a < 901 ) is faster than if( a <= 900 ). Not exactly as in this simple example, but there are slight performance changes on loop complex code. ...
457
votes
5answers
69k views

How do I improve the performance of SQLite? [closed]

Optimizing SQLite is tricky. Bulk-insert performance of a C application can vary from 85 inserts-per-second to over 96 000 inserts-per-second! Background: We are using SQLite as part of a desktop ...
439
votes
23answers
186k views

Tricks to speed up Eclipse [closed]

Which tricks do you know to make the experience with Eclipse faster? For instance: I disable the all the plugins I don't need (Mylyn, Subclipse, …). Instead of using a plugin for Mercurial ...
411
votes
3answers
53k views

Why is my program slow when looping over exactly 8192 elements?

Here is the extract from the program in question. The matrix img[][] has the size SIZE×SIZE, and is initialized at: img[j][i] = 2 * j + i Then, you make a matrix res[][], and each field in here is ...
396
votes
10answers
17k views

Is the recommendation to include CSS before JavaScript invalid?

In countless places online I have seen the recommendation to include CSS prior to JavaScript. The reasoning is generally, of this form: When it comes to ordering your CSS and JavaScript, you want ...
347
votes
2answers
23k views

Why does Python code run faster in a function?

def main(): for i in xrange(10**8): pass main() This piece of code in Python runs in real 0m1.841s user 0m1.828s sys 0m0.012s However, if the for loop isn't placed within ...
311
votes
33answers
30k views

Performance optimization strategies of last resort

There are plenty of performance questions on this site already, but it occurs to me that almost all are very problem-specific and fairly narrow. And almost all repeat the advice to avoid premature ...
264
votes
0answers
56k views

String vs string in C# [duplicate]

Possible Duplicate: In C# what is the difference between String and string In C# the string keyword (highlighted in Visual Studio as a data type) is just a shortcut to the String class ...
257
votes
16answers
80k views

MyISAM versus InnoDB

I'm working on a projects which involves a lot of database writes, I'd say (70% inserts and 30% reads). This ratio would also include updates which I consider to be one read and one write. The reads ...
251
votes
5answers
39k views

Efficiency of purely functional programming

Does anyone know what is the worst possible asymptotic slowdown that can happen when programming purely functionally as opposed to imperatively (i.e. allowing side-effects)? Clarification from ...
237
votes
22answers
86k views

Big O, how do you calculate/approximate it?

Most people with a degree in CS will certainly know what Big O stands for. It helps us to measure how (in)efficient an algorithm really is and if you know in what category the problem you are trying ...

1 2 3 4 5 2107
15 30 50 per page