The sorting ceremony. Is Rust Blazingly Fast?

Is Rust blazingly fast?

The first claim of the Rust language as stated on their web page is “Rust is blazingly fast and memory-efficient: …”.

Around 82,000 developers who participated in the Stack Overflow developer survey had voted Rust as the most loved language not for one year but in a row of five years. Why?

Join me in discovering the secret in this post.

Rust continues to the Most Loved Language
https://insights.stackoverflow.com/survey/2021#most-loved-dreaded-and-wanted-language-love-dread

 I called around 30 programming friends,  around a month back,  to discover the following:

  • Many of you are very enthusiastic and need to know more about its capabilities.
  • Some of you have openly admitted that it is the first time your hear about the Language
  • A material science engineer, turned programmer, is yet to digest this iron content
  • Most of you are too busy with your current assignments and “completablefuture” assignments 

My friends are pragmatic programmers, they are early adopters, highly inquisitive and, of course, they need solid evidence.  As I have a lot of spare time, (like Tokio async I spawn tasks to keep me free), I decided to generate an executive summary about the throughput

எப்பொருள் யார்யார்வாய்க் கேட்பினும் அப்பொருள்
மெய்ப்பொருள் காண்ப தறிவு.  

The great Thirukural emphasis the importance of objective evidence. 

So I was wondering how to show them simple solid evidence.

Like a spark it occurs,  how about we celebrate a sorting ceremony like Hogwarts celebrates their sorting ceremony every year on the 1st Sep. Today it is 11th Sep 🙂

So, I decided to code “Hoare’s  Quick Sort” and “Tim Peter’s Sort” in all the great languages starting from our mother tongue C to every beloved language that includes Python, Java, Go, Rust. As I did not have time I missed my other loved languages like Node.js and Ruby.

Please excuse me. My intention is not to favor any particular language. I love every language. For example, Tim Peter is an exemplified programmer and his algorithm is the winner here not the language, which you are going to see shortly. Sorry, I break the suspense.

Besides, it is an opportunity to bow to these two great computer scientists, Tony Hoare and Tim Peter, and also to enjoy the nostalgic days of recursion.

The benchmarking methodology:

  1. I pre-created 1 million random long numbers and saved them in a text file. This tests data will be used consistently by all future tests.
  2. Then I wrote the Hoar partition in C, Rust, Go, Java and Python. 
  3. The program does two works; reading from the text file to create a collection and performing a sort.
    • We discard the time to read the file to create a collection. It is beyond our scope.
    • We are just interested in the time it takes to perform the sort.
  4. I Repeat the experiments five times
  5. Compute the Average
  6. Compute the number of Sorts we can perform in 1000 ms (1 second) 
  7. Produce a Graph for visualization.

I recorded the time taken for the sorts from a basic droplet from Digital Ocean. Here is the configuration:

Intel(R) Xeon(R) CPU ES-2650L v3 @ 1.80 GHz and running Linux CentOS Version 8

Here is the visualization for you

Number of Quick Sorts Per Second

I used the same data but this time the sorting algorithm is the spectacular Tim Sort’s hybrid merge sort.

Tim Peter is the recipient of the Python Software Foundation’s Distinguished Service Award for 2017 for this major contribution to the Python Programming Language. 

Today, the collection library of many of the modern languages offers an implementation of Tim Peter’s algorithm.  Let us post the implementation of the genius algorithm in Rust on another occasion.

Please note that Go lang does not offer a built-in implementation of Tim Peter’s sort as I observed from the source of Go lang. I believe Go lang selects a quick sort “code path” for this volume of data that uses a different partitioning algorithm.

Fine, Let me confine to just show you the result of the experiment. 

Tim Peter’s Hybrid Merge Sort

Then I could not resist my temptation of benchmarking the algorithms in my MacBook Pro.

Benchmarking in Intel I9 2.3 GHz

Hope I submitted the facts to you.

Here is the link for you to view the making of the experiment

On another occasion let us examine the Memory Safety aspect of Rust.

My sincere Namaskarams to Charles Antony Richard Hoare for his immense contribution to the field of computer science and for his courage to apologize for the invention of the null reference. Dear Hoare, you are a role model and inspiration for us.

Thanks

Leadership, Communication; Culture
What do you think?

Leave a Reply

What to read next