Mark Chavez
eat. sleep. repeat. 👾 coding, ⌨️ keyboarding, 🚴🏼 cycling.
CPU-bound vs IO-bound 03/11/2024

References:
-
https://www.atatus.com/ask/cpu-io-memory-bound
-
https://www.quora.com/What-are-I-O-intensive-workloads

NOTE: This is a compilation of notes I found on the Internet.

CPU-bound
đź’ˇ

We can say that a computer is CPU-bound (or compute-bound) when the time for it to complete a task is correlated to the speed of the central processor. Tasks that do a lot of calculations with comparatively little data are often CPU bound.

Examples:
- Image resizing
- Video editing
- Gaming

In CPU-bound systems, for better performance, it is required to upgrade the CPU than upgrading other components.

IO-bound
đź’ˇ

A system is said to be I/O bound if the time taken to complete a computation is dependent on the period spent waiting for input/output operations to be completed. This is the complete opposite of a system being CPU bound where the tasks are determined solely on the performance of the CPU.

Examples:
- A task that processes data from a disk
- Counting the number of lines in a file
- Network calls

Reading the points out of a file, or fetching them over the internet, or waiting for a user to pick them out with a mouse, is I/O work. Your CPU isn’t doing much except waiting for the disk or server or user to give it the data. It doesn’t matter how fast your code runs if that just means it gets to wait for the next bit of data sooner.

CPU-bound or IO-bound?

To distinguish between CPU-bound and IO-bound tasks, identify whether your task spends more time doing computations or waiting for I/O operations. Profiling tools can provide detailed information about where your program spends its time.

Understanding whether your task is CPU-bound or I/O-bound can help you optimize your code and make it run more efficiently.

The reason this is important is optimization. If your program spends most of its time I/O bound, then it doesn’t matter how much you speed up the CPU work; it’s not going to go any faster. If you want to speed up your program, you have to figure out how to get by with fewer I/O requests, or to make I/O requests that can be handled more efficiently, or something like that, instead of figuring out how to optimize your CPU work.