Questions tagged [performance]

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

The performance of applications is often a paramount concern for mission-critical systems. If your question pertains to optimization, whether it be database queries, algorithms, reducing network/transactional overhead, resource contention, or anything that deals with speed or capacity, consider using this tag.

A good question states performance goals that need to be achieved as well as other restrictions. Trying to optimize something without measuring is not a "performance" question or work, but most likely personal entertainment - expect a question without goals/measurements to be treated as such.

Performance for many programs is represented in big O notation, which classifies how an algorithm's resource requirements change in response to a change in the input size.

This tag can also represent system performance, which is one of the key non-functional requirements of an application or system.

The two main measures of performance are

  • Throughput (how many in a time frame). Example of units: transactions per second (TPS), megabytes per second (MB/s), gigabits per second (Gb/s), messages/request/pages per second.
  • Latency (how long for an action). For example, seek time of 8 ms and search time of 100 ms.

Latency is often qualified with a statistical measure. Note: latencies usually don't follow a normal distribution and have very high upper limits compared with the average latency. As such the standard deviation is not useful.

  • Average latency. The average of all the latencies.
  • Typical or median latency. The mid-point of the range of possible latencies. This is usually 50% to 90% of the average latency. As this is the lowest figure it is often reported by vendors.
  • Percentile latency. The figure which it is less than or equal to N% of the time. That is, 99 percentile if the latency is not more than this, 99 times out of 100.
  • Worst or maximum latency. The highest latency measured.

When seeking to improve performance: prototype and measure first, optimize only if and where needed.

See also:

101189 questions
25 answers

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

In this C++ code, sorting the data (before the timed region) makes the primary loop ~6x faster: #include #include #include int main() { // Generate data const unsigned arraySize = 32768; int…
  • 494,350
  • 52
  • 494
  • 543
56 answers

Which "href" value should I use for JavaScript links, "#" or "javascript:void(0)"?

The following are two methods of building a link that has the sole purpose of running JavaScript code. Which is better, in terms of functionality, page load speed, validation purposes, etc.? function myJsFunc() { alert("myJsFunc"); }
  • 2,737
  • 3
  • 17
  • 5
77 answers

Why is the Android emulator so slow? How can we speed up the Android emulator?

I have got a 2.67  GHz Celeron processor, and 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 for me, it doesn't. I have followed all the…
  • 3,451
  • 3
  • 16
  • 3
24 answers

What is the difference between call and apply?

What is the difference between using Function.prototype.apply() and to invoke a function? const func = function() { alert("Hello world!"); }; func.apply() vs. Are there performance differences between the…
John Duff
  • 38,090
  • 5
  • 35
  • 45
12 answers

Improve INSERT-per-second performance of SQLite

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 application. We have large amounts of configuration…
Mike Willekes
  • 5,960
  • 10
  • 33
  • 33
3 answers

Why is printing "B" dramatically slower than printing "#"?

I generated two matrices of 1000 x 1000: First Matrix: O and #. Second Matrix: O and B. Using the following code, the first matrix took 8.52 seconds to complete: Random r = new Random(); for (int i = 0; i < 1000; i++) { for (int j = 0; j < 1000;…
Kuba Spatny
  • 26,618
  • 9
  • 40
  • 63
12 answers

Why is "1000000000000000 in range(1000000000000001)" so fast in Python 3?

It is my understanding that the range() function, which is actually an object type in Python 3, generates its contents on the fly, similar to a generator. This being the case, I would have expected the following line to take an inordinate amount of…
  • 43,029
  • 15
  • 76
  • 119
7 answers

How does database indexing work?

Given that indexing is so important as your data set increases in size, can someone explain how indexing works at a database-agnostic level? For information on queries to index a field, check out How do I index a database column.
Xenph Yan
  • 83,019
  • 16
  • 48
  • 55
10 answers

Why are elementwise additions much faster in separate loops than in a combined loop?

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 is executed 10,000 times via another outer…
Johannes Gerer
  • 25,508
  • 5
  • 29
  • 35
41 answers

How do I measure elapsed time in Python?

I want to measure the time it took to execute a function. I couldn't get timeit to work: import timeit start = timeit.timeit() print("hello") end = timeit.timeit() print(end - start)
  • 20,223
  • 3
  • 14
  • 3
20 answers

How to efficiently count the number of keys/properties of an object in JavaScript

What's the fastest way to count the number of keys/properties of an object? Is it possible to do this without iterating over the object? I.e., without doing: var count = 0; for (k in myobj) if (myobj.hasOwnProperty(k)) ++count; (Firefox did…
  • 63,493
  • 27
  • 91
  • 122
16 answers

Is < faster than <=?

Is if (a < 901) faster than if (a <= 900)? Not exactly as in this simple example, but there are slight performance changes on loop complex code. I suppose this has to do something with generated machine code in case it's even true.
  • 15,498
  • 3
  • 29
  • 53
34 answers

How do I profile a Python script?

Project Euler and other coding contests often have a maximum time to run or people boast of how fast their particular solution runs. With Python, sometimes the approaches are somewhat kludgey - i.e., adding timing code to __main__. What is a good…
Chris Lawlor
  • 47,306
  • 11
  • 48
  • 68
7 answers

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 z[16] = {1.123, 1.234, 1.345, 156.467, 1.578,…
  • 14,851
  • 3
  • 17
  • 22
11 answers

Replacing a 32-bit loop counter with 64-bit introduces crazy performance deviations with _mm_popcnt_u64 on Intel CPUs

I was looking for the fastest way to popcount large arrays of data. I encountered a very weird effect: Changing the loop variable from unsigned to uint64_t made the performance drop by 50% on my PC. The Benchmark #include #include…
  • 38,535
  • 21
  • 92
  • 152
2 3
99 100