Which of THESE Programming Languages Won on SPEED - Comparing C vs Go vs Rust and More
HTML-код
- Опубликовано: 13 сен 2024
- In this video, we reveal the results for both a speed and memory test comparison on the following programming languages of C, C++, Go, Rust, Python, Javascript and Typescript. The rational is because not only did I want to find the fastest language in terms of low level languages, but I also wanted to compare this to dynamically typed languages like Python in terms of how wide is the gap, really.
The results were extremely interesting. By doing this test, I learned a lot.
To make it repeatable, I ran the test on an Ubuntu 22.04 EC2 x86 server rented from AWS. This was a T2-Medium. Anyone can spin up such a machine, download the code from the GitHub repo and repeat the test pretty easily.
The results are also provided on the shared Google Sheets doc.
What are your thoughts? Do you have experience and helpful critique to add for other viewers? I love learning about all these languages and their trade-offs. Just pick the right tool for the job.
Resources:
Coding Courses:
coderaiders.co...
Coding Packages:
coderaiders.co...
GitHub Url for Speed Test Code:
github.com/cod...
Results Google Sheets:
docs.google.co...
Go vs Rust Related YT Video:
• THIS Is Why You Should...
The obvious reason for the poor results in C and C++ is the fact that you build them without optimizations. In effect, you built their --debug versions, not their --release versions. In your build script, add -O3 to optimize them, and then retime the results.
Additionally, just don't use vector. It is widely considered to be a mistake, and horrendously slow because it attempts to pack multiple bools into a single byte, which makes accessing each one extremely inefficient. I fixed just those two issues and the C++ time was reduced for me from 0.04s to 0.002s.
Worth to mention that his cpp version does only half the work, as it ignores even numbers.
All other tests produce {i -> is_prime(i)}, while cpp - {i -> is_prime(2i+1)}
Thank you!! Well worth a follow up video on the back of this.
Missed opportunity to name it "Kode Kombat"
Lol! I definitely considered it haha.
Noticed your channel is new. I usually don't comment but in these cases i think it would be helpful to mention that the video quality was really nice, watchable and it hooked me like it would from an established channel. Keep it up, you have something nice here!
Wow that was very uplifting to read. Thanks for the encouragement!
YOU EVEN MADE THE TOWERS , I AM DONE 😂 i love this
Hey i'm lovin the video.
I actually like to write these performance benches by hand (~ not using any library).
Those i specialized on: C, Rust, Zig and Python/Cython. Wrote maybe 10+ different benches..including prime numbers but not using the method you got here.
Later I will write my own and then compare the results. Cheers!
here goes my numbers for C and Rust (average of 10 loops):
*primes < 10mil:
C = 83ms
Rust = 99ms
*primes < 500mil:
C = 6,030ms ; memory 477-550MB ; CPU 15-16%
Rust = 6,041ms ; memory 477-640MB ; CPU 15-17%
*exe file:
C = 22KB
Rust = 152KB
In my experience writing these benches, the result above is within expectation.
I used the --release flag when compiling Rust and -O3 for C.
Later I'll do Zig as well.
added Zig numbers:
*primes < 10mil:
Zig = 64ms
*primes < 500mil:
Zig = 5,704ms memory 477-490MB CPU 15-16%
*exe file:
Zig = 664KB
used -O ReleaseFast flag to compile the Zig file.
Everybody is a self-taught developer to a certain extent mate. I did my bachelors, then after 15 years in the industry, I went to get my master in software engineering. What you learn on your own by digging through resources, seeking out courses, building projects, and developing yourself over time makes you much better at your craft than any 3/4/5/6-year education in college or university. Keep being curious and self-critical, keep learning and diving outside of your comfort zone, and you'll be great. Loved the video. And isn't Rust great? Love it!
Definitely. Really like Rust. Can't stop working with it. Thanks for the kind encouragement!
@@coderaiders-yt Same. It's definitely one of the nicest languages I ever worked with.
So in mortal Kombat world c and c++
Would be k and k++ ?
I think Zig and Kotlin would be very interesting/to add to the test.
There is always a big difference between standard lib code and highly optimized code. A good reference are the following pages (since youtube is VERY restrictive on external links, I'll throw some keywords to google in ...a quick search should do the rest):
* benchmarksgame team
* programming language benchmarks vercel
And as a functional programming language of course: Haskell
Lovely addition, thank you
If you like Python syntax and speed of Rust, look at Nim language. IMHO Nim syntax is even cleaner than Python, but it is a tiny bit more symbol-heavy compared to Python.
And as a video idea, It would be fun to race Rust against Nim, Zig and GO
Cool idea and feedback. Thank you!
The fact that your C++ results are worse than C is ridiculous. You could just compile your C example with a C++ compiler for exactly the same performance. You also don't need to use memset... but whatever. Terrible analysis.
Yeah, you're right on the C++ vs C. Not sure I appreciated the sentiment. But fair.
❣️ "promo sm"
:-)