Speed Testing Programming Languages

When I was a young 12-year-old in the early 80’s, I was fortunate enough to acquire a Commodore Vic 20, which was my first computer. From there, I graduated to the Commodore 64, which, even today, remains one of the most iconic personal computers of the 1980s. With its 8-bit processor and a minimal 64 kilobytes of RAM, it wasn't just a machine; it was a gateway to the digital frontier. I became obsessed with writing software for the Commodore. While writing software, I was also interested in making it faster. Between basic and/or assembler, depending on what you used, you could significantly increase the speed of the 6502 microprocessor that was internal to the Commodore 64.

A Brief Overview of programming languages

As we all know, Programming languages are tools used by developers to communicate instructions to computers. As there are many different languages, each language has its purpose. I chose to test some of the more popular languages today.

  • Python: Known for its readability and versatility, Python is widely used for web development, data analysis, artificial intelligence, scientific computing, and automation.
  • JavaScript: The backbone of web development, JavaScript is used to create interactive and dynamic web pages. It runs on the client side and is supported by all modern web browsers.
  • Java: A versatile and platform-independent language, Java is used in various applications, from enterprise-level systems to Android app development.
  • C: One of the oldest programming languages, C is known for its performance and is commonly used in system programming, game development, and embedded systems.
  • C# (C-sharp): Developed by Microsoft, C# is used primarily for developing Windows applications and games using the Unity game engine.
  • Rust: Known for its simplicity and productivity, Rust is an exciting and relatively modern programming language that has gained a lot of traction in recent years, especially among systems programmers.

As I said, this list is just the tip of the iceberg. Each programming language has its unique features, strengths, and use cases.

Why run Speed Tests?

Running speed tests on programming languages I feel can be important for several reasons, especially in the context of performance-critical applications. As I said, I enjoyed doing this on the Commodore 64, trying to optimize code and make a program better. Today, arguably, it’s not as important as there are other factors to consider when building applications for business. Here are some key reasons to speed-test your programming language.

  • Performance Benchmarks: Speed tests help determine how fast a programming language can execute specific tasks. This is crucial for applications where performance is a key factor, such as real-time systems, game development, and high-frequency trading.
  • Efficiency Comparison: By running speed tests, developers can compare the efficiency of different languages for a particular task. This helps in choosing the most suitable language for a project based on its performance characteristics.
  • Optimization: Speed tests can identify bottlenecks in code and highlight areas that need optimization. This is valuable for improving the overall efficiency and responsiveness of an application.
  • Scalability: Performance tests can assess how well a language scales with increased load or data size, which is essential for applications expected to handle large volumes of data or high user traffic.

For example, if you're developing a high-performance web server, running speed tests on different languages like C/C++, Rust, and Python can help you decide which one offers the best performance and resource management. But as I said above, speed may not be the only deciding factor when choosing a development language such as,

Choosing a programming language involves more than just performance considerations. Here are some reasons you might choose a slower language.

  • Ease of Use and Readability: Languages like Python and Rust are known for their simple and readable syntax, making it easier to write, maintain, and debug.
  • Development Speed: Faster development cycles can be more valuable than raw performance. Languages like Python and JavaScript enable rapid prototyping and iteration, which can be critical for startups or fast-moving projects.
  • Community and Ecosystem: A strong community and extensive libraries or frameworks can significantly reduce development time. For example, JavaScript has a vast ecosystem for web development, and Python has extensive libraries for data science and machine learning.
  • Cross-Platform Compatibility: Some languages offer better cross-platform support. For instance, Java is designed to run on any platform with its JVM (Java Virtual Machine), making it a good choice for applications that need to run on multiple operating systems.
  • Developer Expertise: Leveraging the skills and expertise of your development team is crucial. If your team is proficient in a particular language, it might be more efficient to use that language rather than learning a new one.

However, this is a briefing about the speed of 6 different programming languages. So, let’s dive into what I found.

Performance Insights

Through speed testing, several interesting facets of each language came to light. The test that was used was a loop that iterated 1,000,000 times with no instruction set. I call it the “1MLT” speed test.

Conducted on (Machine Specs)

  • Architecture: x86_64
  • CPU op-mode: 64-bit
  • CPU(s): 4
  • Thread(s) per core: 2
  • Core(s) per socket: 2
  • Model name: AMD Ryzen Embedded R1606G with Radeon Vega Gfx
  • RAM: 8GB

Language C

C is a sturdy foundation that many modern programming languages are built on. I actually started years ago in the C Language, and here are the reasons you may want to use C.

  • Efficiency and Performance: C programs are often faster and more efficient, making them ideal for system-level programming.
  • Portability: C code can be run on various platforms with minimal changes. This makes it highly portable.
  • Control and Flexibility: You get more control over hardware resources and memory management, which is crucial for system-level programming.

Language C#

C# is a versatile and powerful programming language developed by Microsoft. Here are some key reasons why you might choose to use C#:

  • Modern and Robust: C# is designed for modern application development, with features that make it easy to build a wide variety of applications.
  • Object-Oriented: C# is an object-oriented programming language, which makes it easier to manage and organize complex programs.
  • Cross-Platform: With .NET Core, C# applications can run on multiple platforms, including Windows, macOS, and Linux.
  • Extensive Library: C# comes with a rich library of built-in functions and classes, making it easier to perform common tasks and build complex applications.

Language RUST

Rust is a language that's been gaining a lot of attention for its focus on performance, safety, and concurrency. Here are some compelling reasons to consider using Rust.

  • Memory Safety: Rust guarantees memory safety without needing a garbage collector. It uses a system of ownership with rules that the compiler checks at compile time, which helps prevent null pointer dereferencing and buffer overflows.
  • Performance: Rust is designed to be as fast as C and C++, making it suitable for system-level programming where performance is critical.
  • Concurrency: Rust makes it easier to write safe and concurrent code. Its ownership system helps ensure that data races are eliminated at compile time, making concurrent programming more manageable.
  • Modern Features: Rust provides modern programming features like pattern matching, type inference, and trait-based generics, making it more expressive and easier to write complex programs.

Language PYTHON

Python is incredibly popular, and for good reason! It is actually my preferred language today.

Here are some top reasons to consider using Python.

  • Ease of Learning and Use: Python's syntax is clear and easy to learn, making it a great choice for beginners and experienced developers alike.
  • Versatility: Python is a general-purpose language that can be used for web development, data analysis, machine learning, automation, scripting, and much more.
  • Extensive Libraries and Frameworks: Python boasts a vast ecosystem of libraries and frameworks, such as NumPy, Pandas, TensorFlow, Django, and Flask, which make development faster and easier.
  • Community Support: Python has a large and active community, which means you'll find plenty of resources, tutorials, and forums to help you with any questions or problems.
  • Cross-Platform: Python is cross-platform, meaning you can run your code on various operating systems, such as Windows, macOS, and Linux, without modification.
  • Readable Code: Python's emphasis on readability and simplicity means that your code is more maintainable, extendable, and easier to understand.

Language NodeJS

Node.js is a popular choice for building server-side applications. Great if you already know JavaScript and has been around for some time. Here are some compelling reasons to consider using Node.js.

  • JavaScript Everywhere: With Node.js, you can use JavaScript for both the front end and the back end, which streamlines development and allows for code reuse.
  • Fast and Scalable: Node.js is built on the V8 JavaScript engine, which makes it very fast. Its event-driven, non-blocking I/O model is excellent for building scalable applications.
  • Large Ecosystem: The Node.js ecosystem is extensive, with npm (Node Package Manager) offering a vast array of libraries and modules that you can easily integrate into your projects.
  • Real-Time Applications: Node.js is well-suited for building real-time applications, such as chat applications and online gaming, thanks to its asynchronous nature.
  • Active Community: Node.js has a large and active community that provides plenty of resources, tutorials, and support.

Language Java

Java is a widely used programming language that's renowned for its portability, scalability, and robustness. Great for building desktop applications, web applications, or mobile apps. Here are some key reasons to consider using Java.

  • Platform Independence: Java applications are compiled into bytecode that can run on any device equipped with the Java Virtual Machine (JVM), making Java highly portable across different operating systems.
  • Object-Oriented: Java is an object-oriented programming language, that helps in organizing complex programs and promoting code reuse through inheritance and polymorphism.
  • Robust and Secure: Java provides strong memory management, exception handling, and a security model that helps in building reliable and secure applications.
  • Rich API and Libraries: Java comes with a vast standard library and a rich set of APIs that simplify development and allow developers to build feature-rich applications more quickly.
  • Scalability: Java is designed to scale well, making it an ideal choice for large-scale enterprise applications, such as banking and e-commerce systems.
  • Community Support: Java has a large and active developer community, providing plenty of resources, frameworks, and tools to support development.
  • Performance: Java's Just-In-Time (JIT) compiler and efficient garbage collection contribute to its high performance, making it suitable for both client-side and server-side applications.

Findings

As I figured when writing this code. C Code would be the most performant. But there were a couple of surprises.

The first one is Rust. It tested very slowly at first. I am new to the Rust programming language. I found that to be very strange, given the fact that it is specifically designed to be fast. So, I did some digging, and it turns out that the Rust compiler has optimization levels. So, it should be noted for anyone new to Rust that when you have production code, make sure you optimize it when compiling. I found it interesting that there was a massive speed difference between the Non-optimized code and the Optimized release code. So, I included it in the results.

The second surprise I had was Python tested very fast for being an interpreted language. From the tests I ran, it turns out that Python was the second fastest behind C. So i did some more digging and there are reasons that this may have occurred.

  • Implementation Details: The way the loop is implemented in each language can affect performance. For example, if the Rust loop includes additional safety checks or complex operations, it might be slower than a more straightforward Python loop. However, this was not the case. So, I am ruling this one out.
  • Runtime Behavior: Python's runtime and libraries, such as NumPy for numerical operations, are highly optimized and use compiled C code under the hood. In such cases, Python can outperform poorly optimized or non-release Rust code. Yes, this may be the case for the non-optimized Rust code, but it should not be the case for the optimized Rust code, as Python was still faster.
  • Garbage Collection: Rust’s memory management is manual (ownership and borrowing), which might require more careful and explicit handling compared to Python’s automatic garbage collection. In some cases, manual management can introduce overhead if not done efficiently. However, this should not be the case, as there was very little variable manipulation.

I would be interested in readers' thoughts if you would like to drop me a message: ([email protected])

Results Table

Results Table

Testing Results

Conclusion

Basically, I created this briefing as I enjoy writing and testing code in a variety of languages. Of course, there are many different variables that can affect the speed and responsiveness of an application. There are many different and distinct reasons to choose one programming language over another programming language. But in my mind, it comes down to two reasons. The first one is execution speed. Some languages, like C, C++, and Java, are renowned for their fast execution times, making them suitable for performance-critical applications such as video games or high-frequency trading systems.

The second one, and maybe the most important, depending on what you are building, is development speed. Higher-level languages like Python or JavaScript might not be the fastest in execution but often allow for quicker development and iteration, which can produce massive benefits for the enterprise software cycle. However, in this test, Python performed very well.

As a surprise, it turns out Python was faster than I thought, and Rust was much slower than I thought it would be. I really thought it would be closer to C. When you do these tests and find surprises, at least for me, it gives me the feeling of accomplishment through proof.

I really enjoyed writing and testing each different language. Knowing that each has pros and cons. Hopefully, this gives you a pretty good idea of which language you might be capable of and perhaps motivates you to do some of your own.

I appreciate your reading.

Craig Breakspear

Up Next
    Ebook Download
    View all
    Learn
    View all