How many CPU cores do I need?

In the 3rd installment of the Beginners guide to programming, we will explore Central Processing Unit (CPU) and its role in the computer system and programming. I hope that you remember everything from first and second level programming guide. If not, you can refresh your memory before you jump into this one.

We will start exploring CPU role from the perspective of simple question many people are asking these days which is: How many CPU cores do I need?

We’re bombarded with all kinds of marketing which involve bragging about how many cores has some new mobile phone, tablet, laptop or desktop. A few years ago it was all about frequency, MHz, GHz, etc. So what does it actually mean?

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 convert 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 less space as possible. Common image compressions are JPG, PNG, GIF, etc. CPU also perform some controlling operations regarding other system components and generally any kind of processing. Any part of the system which needs any kind of calculation can deploy CPU but most of the time operating system and other software are the most intensive users.

CPU has its own instructions set, which is some kind of low-level programming language (known as Assembler). So if you want to be a major geek, but real one, not Facebook or Twitter bragging script kiddie, you may learn to program with CPU instructions language. However, coding in Assembler is extremely slow and error-prone process so not many people are doing it. Moreover, there are 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 fastest and most optimized if written properly.

But all other higher level programming languages(C, C++) are automatically translating into CPU instructions for different architectures so there’s usually no need to mess directly with CPU instructions. Now is the right time to mention even higher level programming languages, like PHP or Javascript which are not translating into CPU instructions but use an additional layer of software known as the interpreter or virtual machine. Specifically, Javascript uses interpreter bundled with your browser (all modern browsers support Javascript). There’s also the NodeJS server which also has Javascript interpreter built in. Because of that additional layer of execution interpreting programming languages are slowest but cross-platform which means you write the same code for all different processors and operating systems.

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 total collapse of the system (but many times it fails). So each OS requires some additional specific programming. Sometimes it’s done on interpreter level (so you don’t need to worry about it) and sometimes it’s programer’s job.

But what are cores and how many I need? Well, cores are concept introduced a few years ago when CPU manufacturers reached the wall with their current technologies. Before that, CPU advancements ware 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 do 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 haven’t noticed 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 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 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 phones. 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 specific feature like a number of cores. Read as many reviews as possible before you buy.

Remember: 

CPU is the part of the computer system which actually does the data processing. It may have multiple cores which means it can process multiple processes in parallel. There are few different CPU architectures with different instruction sets. CPU instruction sets are the basis of higher-level programming languages, like C or C++. There are also higher-level programming languages like Javascript or PHP with an additional processing layer called interpreter or virtual machine.

CPU also has its internal memory for performing basic operations but the most of time in programming you won't be able to access that memory.

You’re now ready for the next level where we’re going to deepen your knowledge about programming. Stay tuned for networking guide for beginner developers or development beginners. Funny thing that role now changed its name from programmer to fancier – developer. It’s kinda stupid.

Leave a Reply

Your email address will not be published. Required fields are marked *