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:

93482 questions
867
votes
3 answers

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 (Note: The timing is done with the time function in BASH in Linux.) real 0m1.841s user 0m1.828s sys 0m0.012s However, if the for loop isn't…
thedoctar
  • 8,353
  • 3
  • 18
  • 30
858
votes
15 answers

Efficiency of Java "Double Brace Initialization"?

In Hidden Features of Java the top answer mentions Double Brace Initialization, with a very enticing syntax: Set flavors = new HashSet() {{ add("vanilla"); add("strawberry"); add("chocolate"); add("butter…
Jim Ferrans
  • 29,162
  • 12
  • 52
  • 83
813
votes
12 answers

How to create a new object instance from a Type

One may not always know the Type of an object at compile-time, but may need to create an instance of the Type. How do you get a new object instance from a Type?
tags2k
  • 70,860
  • 30
  • 74
  • 105
796
votes
9 answers

What is a "cache-friendly" code?

What is the difference between "cache unfriendly code" and the "cache friendly" code? How can I make sure I write cache-efficient code?
Noah Roth
  • 8,210
  • 5
  • 17
  • 24
785
votes
14 answers

Count(*) vs Count(1) - SQL Server

Just wondering if any of you people use Count(1) over Count(*) and if there is a noticeable difference in performance or if this is just a legacy habit that has been brought forward from days gone past? The specific database is SQL Server 2005.
super9
  • 26,033
  • 36
  • 110
  • 168
774
votes
2 answers

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 made to be the average of the 9 fields around it in…
anon
738
votes
5 answers

Why is [] faster than list()?

I recently compared the processing speeds of [] and list() and was surprised to discover that [] runs more than three times faster than list(). I ran the same test with {} and dict() and the results were practically identical: [] and {} both took…
Augusta
  • 6,511
  • 4
  • 21
  • 38
725
votes
12 answers

Why shouldn't I use PyPy over CPython if PyPy is 6.3 times faster?

I've been hearing a lot about the PyPy project. They claim it is 6.3 times faster than the CPython interpreter on their site. Whenever we talk about dynamic languages like Python, speed is one of the top issues. To solve this, they say PyPy is 6.3…
chhantyal
  • 10,570
  • 6
  • 45
  • 71
697
votes
18 answers

Speed comparison with Project Euler: C vs Python vs Erlang vs Haskell

I have taken Problem #12 from Project Euler as a programming exercise and to compare my (surely not optimal) implementations in C, Python, Erlang and Haskell. In order to get some higher execution times, I search for the first triangle number with…
Hyperboreus
  • 29,875
  • 7
  • 42
  • 78
694
votes
8 answers

Which Python memory profiler is recommended?

I want to know the memory usage of my Python application and specifically want to know what code blocks/portions or objects are consuming most memory. Google search shows a commercial one is Python Memory Validator (Windows only). And open source…
Anurag Uniyal
  • 77,208
  • 39
  • 164
  • 212
659
votes
7 answers

When to use CouchDB over MongoDB and vice versa

I am stuck between these two NoSQL databases. In my project I will be creating a database within a database. For example, I need a solution to create dynamic tables. So users can create tables with columns and rows. I think either MongoDB or…
Luke101
  • 56,845
  • 75
  • 204
  • 330
627
votes
9 answers

Which method performs better: .Any() vs .Count() > 0?

in the System.Linq namespace, we can now extend our IEnumerable's to have the Any() and Count() extension methods. I was told recently that if i want to check that a collection contains 1 or more items inside it, I should use the .Any() extension…
Pure.Krome
  • 78,923
  • 102
  • 356
  • 586
622
votes
20 answers

Preferred method to store PHP arrays (json_encode vs serialize)

I need to store a multi-dimensional associative array of data in a flat file for caching purposes. I might occasionally come across the need to convert it to JSON for use in my web app but the vast majority of the time I will be using the array…
KyleFarris
  • 16,408
  • 4
  • 40
  • 40
617
votes
34 answers

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 optimization. Let's assume: the code already is…
jerryjvl
  • 18,001
  • 6
  • 38
  • 55
600
votes
23 answers

What's the best way to convert a number to a string in JavaScript?

What's the "best" way to convert a number to a string (in terms of speed advantage, clarity advantage, memory advantage, etc) ? Some examples: String(n) n.toString() ""+n n+""
Pacerier
  • 76,400
  • 86
  • 326
  • 602