In this guide, we will explore Central Processing Unit (CPU) and its role in the computer system and programming.
We will start exploring CPU role from the perspective of a simple question people ask themselves: How many CPU cores do I need? In addition to this, we will try to answer should a software development computer have as many cores as possible?
We’re bombarded with all kinds of marketing which involve bragging about how many cores a new mobile phone, tablet, laptop, or desktop has. A few years ago it was all about frequency, MHz, GHz, etc. So what does it actually mean?
What is CPU?
CPU is the core part of a computer system and its main role is information processing. For example, before your computer or phone displays an image on the screen CPU actually reads image data from file storage and converts binary data to the actual visual representation of that image on the screen. In the process, CPU will do many operations like decompressing image data which is stored in a compressed format on disk to occupy as little space as possible. Common image compressions are JPG, PNG, GIF, etc. CPU also performs some controlling operations regarding other system components and generally any kind of processing. Every part of the computer system which needs some computation can deploy CPU but most of the time operating systems and other software are the most intensive users. It’s worth mentioning that CPU is used for general processing and some specific operations and algorithms like math calculations which are important in images and video processing but are better served by GPU (Graphics Processing Unit). GPUs are embedded in the graphics cards.
CPU and low level programming
CPU has its own instructions set, which is some kind of low-level programming language, known as Assembler. Thus, if you want to be a major geek – a real one, not some Facebook or Twitter bragging script kiddie, you should learn to program with CPU instructions language. However, coding in Assembler is an extremely slow and error-prone process so not many people are doing it. Moreover, there are a few different CPU architectures with its own instruction sets, so to support more than one architecture you would have to learn all those instruction sets. On the other side, programs in Assembler are the fastest and most optimized if written properly.
CPU relation with high level programming languages
Operating systems and CPU
There’s one more thing to keep in mind when talking about how your program reaches CPU. Operating systems (MacOS, Linux, Windows, Android ..) are positioning itself as some kind of CPU managers, so your program, even if it’s written in Assembler using CPU instructions, needs to pass the operating system check. Usually, OS tries to guard CPU against overuse which can lead to a total collapse of the system (but many times it fails). So each OS requires some additional specific programming. Sometimes it is done on an interpreter level (so you don’t need to worry about it) and sometimes it’s programmer’s job.
So should I buy CPU with as many cores as possible?
What are cores and how many cores do I need? Well, cores are a concept introduced a few years ago when CPU manufacturers hit a wall with their current technologies. Before that, CPU advancements were measured by CPU frequency so we first had CPU speed measured in KHz, then MHz, and finally in GHz. Then manufacturers introduced the idea of parallel processing (which is not new because you already had multiprocessor solutions), but this time it was on the level of one processor. So you got the core as a parallel processing unit. For example, if you have CPU with two cores that means your system can process two activities at the same time. But you were always able to run more programs at the same time even before cores technology. Actually, you haven’t but your CPU was fast enough and you couldn’t notice that it temporarily stopped processing in one program to allocate more resources to other. Now, with multiple cores, you have real multiprocessing in place.
But this is not the end of the story about cores. In the past, it was easy because if you had a faster frequency it would be usually better (anyone remembers AMD CPU’s heating issues?) Now you have the number of CPU cores and core frequency. It’s not easy to say if it’s better to have more cores with lower frequency or fewer cores with higher frequency. It very much depends on the operating system and the software’s ability to utilize those cores in the most optimal way. To make things more complicated one CPU could have multiple cores with different frequency. This is especially true with smartphones. If you see the advertisement that some new phone has 15 cores it might actually run slower than some phone with fewer cores and higher frequency. And the concept of cores is quite dependent on OS management. So when buying a new product (phone or computer) it’s better to try to evaluate the whole product rather than a specific features like a number of cores. Read as many reviews as possible before you buy.
It’s not of much difference in the context of the development computer. As a software developer you will need a processing power to do things like writing code, compiling and building application, testing and debugging application, deployment. Some IDEs (Integrated Development Environments) are quite robust and require a lot of processing power. Moreover, you may need to start VM (Virtual Machine) or environment emulator like when you’re making and testing smartphone applications on your computer system. These are also CPU intensive tasks but as I already said it depends on how good some specific VM or emulator is utilizing CPU cores which is something out of your control.