When Speed Matters: Comparing Rust and C++

C++ is a venerable programming language with over thirty-six years, can the newcomer Rust match its versatility and speed?
Share on facebook
Share on twitter
Share on linkedin

Get the best of
The Daily Bundle in your inbox every week

Get the best of The Daily Bundle in your inbox every week

C and its object-oriented cousin C++ are 2 of the most well-known and venerable programming languages on the market. When speed is the main factor in software or when resource management is an issue, these 2 languages are still the default go-to, even decades after their creation. 

Every few years or so, another group will try to develop and release what has come to be known as “C killers”, programming languages designed from the ground up to provide the same benefits as the C family while dealing with some of the most well-known issues at the same time. 

Just as an example, we have Java and C#, both of which are amazing and have built great resources and communities. If you take into account the mobile market, Java is probably the most used programming language in the world. 

Rust, a powerful all-purpose fast programming language focused both on safety and performance, is one of the latest languages touted as a “C-killer.” Unfortunately for those eager to see the C family gone forever, it doesn’t seem like Rust will be the chosen one. Nevertheless, Rust does a lot of things right, and it’s an amazing alternative for people who are looking for powerful programming languages with modern sensibilities. 

Before we begin a word of caution: this isn’t about speed. Objectively comparing the speed of programming languages is difficult, as there are many variables involved, from how each language handles certain tasks to the experience and inventiveness of the developer who is writing the code.

A quick example: Python is considered one of the slowest languages on the market, but an advanced Python developer can make faster programs than a person who’s working on C for the first time.

Now that we got that out of the way, let’s dive into Rust’s features and compare them to C++ to check which one is best. 

High-level and low-level

Both C++ and Rust are considered “low-level” languages, or at least lower-level than other popular high-level languages like Javascript or the aforementioned Python. But what does that mean exactly?

Computers follow arithmetic and logical instructions to accomplish whatever task they have been programmed to do. For example, to display the text you’re reading right now, your CPU is sending it a signal via electrical currents giving instructions on the color of each pixel, creating the image you are seeing.

A computer doesn’t know what the letter A is, but by following mathematical instructions it can draw it on a screen. Those instructions are called machine code. At the other end of the spectrum, you have natural language, the way we humans speak and communicate with one another.

A programming language serves as an intermediary between machine code and human language. When someone says that a programming language is low level, what they are saying it’s that it’s closer to machine code than to the way we speak.

The higher level a language is, the more it looks like human language, but at the same time the more processing power it takes to turn that program into machine code. That’s why languages like Python are very readable but are also slow and unoptimized.

Suffice to say, Rust and C++ fill a very similar need, that is, a code that it’s readable but that can run fast enough for heavy-lifting software like operating systems or drivers.

Rust: Security first

Rust was created in 2010 by the Mozilla Foundation. It started as a side project of one of the developers that quickly grew as the foundation realized the potential it had for developing their software. An assessment that proved to be true since in its short lifespan Rust has become one of the most loved programming languages by developers.

One of the biggest reasons why that happened is that Rust has 2 killer features that make it stand out among its peers: safe concurrency and memory safety.

Concurrency is the ability of a program or software to execute several of its parts out of order and/or in a partial order, which in turn means that you can have parallel execution of concurrent processes.

Let’s say that you have a program with 10 instructions. Instead of having to run each one at a time, you can have several processors running several instructions concurrently reaching the same result in less time.

While other languages leave the threading up to the developer, manual threading requires a level of knowledge that not every developer has. Rust checks for Ownership statically to make sure that a developer isn’t inadvertently creating a bug by having the program access information when it shouldn’t. 

The same goes for memory management. Typically, memory is either handled by the developer directly or left to what is known as garbage collecting, that is, letting the computer figure out what information is no longer being used, and freeing up the memory. 

While garbage collecting is amazing, it can be pretty slow and expert developers often find it constraining. Instead of GC, Rust avoids null pointers, dangling pointers, or data races all together with safe code. Fewer bugs all around imply faster development times.

To put it simply, Rust is like driving a racing car with a safety belt: it’s a lifesaver for someone who is just learning how to drive and it’s a good safety measure for an expert driver, even if they are unlikely to crash. That’s what memory safety is all about. 

C++: The tinkerer’s dream

C++ is 36 years old, and in that time it has garnered thousands upon thousands of libraries as well as a knowledge base that it’s simply baffling. No matter how crazy or out there your idea is, odds are that someone has already done something like it in C++.

Additionally, C++ is a tinkerer’s dream come true. Few languages give as much freedom to the developer as the C family. Like a finely-tuned Stradivarius, it’s a tool that in the hands of a maestro can truly create a work of art. 

Do you have Windows OS? You are using C++. Do you like YouTube? That’s the language that handles the video processing. Ever played a game made in the Unreal engine? That’s running on C++ as well. There isn’t a better poster child for the concept of multipurpose language.

As a company looking for developers, the talent pool for C++ programmers is a thousand times bigger than Rust, at least for now. Who knows what the distribution will look like in 10 years? 

More libraries mean less development time as there are more tools out there to be freely used by developers and, all in all, there is plenty of evidence that points that C++ is still the fastest object-oriented language available. 

Which one to pick?

This comparison is quite a toss-up, and it would be a disservice to point at one language and declare it a winner. Fortunately, there doesn’t have to be one: Rust and C++ are very similar and integration between them is possible. Both languages have proven themselves invaluable assets in software development. 

If your project requires speed then you can’t go wrong with either choice, it’s a preference between the safety of Rust or the customizability of C++.

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments

How useful was this post?

Click on a star to rate it!

Please enter a valid E-mail address.

Get in Touch

Access the Top 1% IT Talent, leverage our expertise to
jump-start your business.​

  • This field is for validation purposes and should be left unchanged.
If you previously need to sign a non-disclosure agreement, please email us at [email protected].
Scroll to Top

Get in Touch

Jump-start your Business with the
Top 1% of IT Talent.

Need us to sign a non-disclosure agreement first? Please email us at [email protected].

ACCELERATE YOUR DIGITAL TRANSFORMATION

By continuing to use this site, you agree to our cookie policy.