Performance Properties

Learn about different aspects of performance to speed up the execution time.

Aspects of performance

Before we start measuring, we must know which performance properties are important for the application we are writing. In this section, we will know some frequently used terms when measuring performance. Depending on the application we are writing, some properties are more relevant than others. For example, throughput might be a more important property than latency if we are writing an online image converter service, whereas latency is key when writing interactive applications with real-time requirements. Below are some valuable terms and concepts that are worth becoming familiar with during performance measurement:

  • Latency/response time: Depending on the domain, latency and response time might have very precise and different meanings. However, in this course, we mean the time between the request and the response of an operation—for example, the time it takes for an image conversion service to process one image.

  • Throughput: This refers to the number of transactions (operations, requests, and so on) processed per time unit—for example, the number of images that an image conversion service can process per second.

  • I/O bound or CPU bound: A task usually spends the majority of its time computing things on the CPU or waiting for I/O (hard drives, networks, and so on). A task is said to be CPU bound if it would run faster if the CPU were faster. It's said to be I/O bound if it would run faster by making the I/O faster. Sometimes you hear about memory-bound tasks too, which means that the amount or speed of the main memory is the current bottleneck.

  • Power consumption: This is a very important consideration for code that executes on mobile devices with batteries. In order to decrease the power usage, the application needs to use the hardware more efficiently, just as if we are optimizing for CPU usage, network efficiency, and so on. Other than that, high-frequency polling should be avoided since it prevents the CPU from going to sleep.

  • Data aggregation: It's usually necessary to aggregate the data when collecting a lot of samples during performance measurement. Sometimes mean values are a good enough indicator of how the program performs, but more often, the median tells us more about the actual performance since it's more robust against outliers. If we are interested in outliers, we can always measure min and max values (or the 10th percentile, for example).

This list is by no means exhaustive, but it's a good start. The important thing to remember here is that there are established terms and concepts that we can use when measuring performance. Spending some time defining what we really mean by optimizing code helps us reach our goals faster.

Speedup of execution time

When we compare the relative performance between two versions of a program or function, it's customary to talk about speedup. Here we will see a definition of speedup when comparing execution time (or latency). Assume we have measured the execution times of two versions of some code: an old slower version, and a new faster version. The speedup of execution time can then be computed accordingly:

Get hands-on with 1200+ tech skills courses.