At the start of the year I wrote a blog entry outlining my goals for the year, specifically: Learn Rust. Use it to build a StarCraft bot. Climb three new mountains. Complete the Mazamas Intermediate Climbing School (ICS) I accomplished the first goal pretty early on. You can read about it here. The second took a little longer, but I eventually summitted three new mountains, Mt. Hood, Old Snowy, and Three Finger Jack.
The past couple months I’ve been working my way through different LeetCode problems because they force me to grapple with challenges that I don’t really see in my day to day work. I’ve shifted from HackerRank in order to increase the variety of questions that I see. The problems I’ve been working on are part of a curated set called “LeetCode 75”. These cover string operations, two pointer problems, sliding windows, prefix sums, stacks, queues, linked lists, binary trees, graphs, depth first/breadth first search, heaps, bits, and dynamic programming.
Last month’s article foreshadowed this article’s topic a bit with the sources cited at the bottom. ChatGPT generated the Rust code snippets after I told it “Write a Rust queue using a linked list.” I had to specify that it use a linked list, otherwise ChatGPT would have imported the Rust queue library which uses a less efficient vector implementation. DALL-E generated the image when provided the title of the article, “Rust queue performance.
After creating my Starcraft Rustbot and then comparing queue performance in Kotlin and Swift, I naturally began to wonder about the performance of a queue in Rust. How would a language billed as performant as C compare? Are there truly significant gains for operating “close to the metal”, or have the Swift and Kotlin compilers developed to a point where they can optimize to a similar level of performance? Below is the implementation for my Rust queue:
I’ve used HackerRank throughout my career, both when I’ve been screened as a candidate, as well as to screen my own candidates. I’ve also used it to study algorithms and data structures. It’s a great platform for practicing and evaluating the fundamentals of Computer Science. In the process of skills evaluation the candidate must check a box stating “I will not consult/copy code from any source including a website, book, or friend/colleague to complete these tests, though may reference language documentation or use an IDE that has code completion features.