Logo

dev-resources.site

for different kinds of informations.

SORRY, RUST & DEVS !

Published at
3/29/2024
Categories
rust
codenewbie
clang
testing
Author
bekbrace
Categories
4 categories in total
rust
open
codenewbie
open
clang
open
testing
open
Author
8 person written this
bekbrace
open
SORRY, RUST & DEVS !

Hi!
Today, I will be comparing - for the second time: C and Rust in terms of speed to count till 500M.
But before we jump in, let's address something real quick.

Sorry, Folks!

Last time I talked about C and Rust, I got hit with a wave of comments – some of them pretty passionate, I might add. Seems like I missed the mark with some of the code examples.
Some comments were pretty harsh - here, on Twitter and on YouTube, and somewhat lacked politeness - My advise, if you want to correct someone, do it with humbleness and respect.
In general, your feedback is precious (for the majority of adequate readers / viewers), and I'm here to set things straight.
So, grab a cup of coffee, and let's dive back in.

1- C

C is 50 years old !
It's like that vintage car your grandpa swears by – reliable, sturdy, but not without its quirks.
Take a look to my first test in C:

#include <stdio.h>
#include <time.h>

int main() {
    clock_t start_time = clock();

    unsigned long long count = 0;
    unsigned long long target = 500000000;

    while (count < target) {
        count++;
    }

    time_t end_time = time(NULL);
    double elapsed_time = difftime(end_time, start_time);

    printf("Counting to %llu took %f seconds.\n", target, elapsed_time);

    return 0;
}
Enter fullscreen mode Exit fullscreen mode

The count ended in ... well, take a look to the video :)

Now, I am not a savvy in neither C nor Rust, but I have a pretty solid foundation in C at least, and C's like that buddy who's been with you through thick and thin.
C is your best school friend, but you gotta watch your feet: Manual memory management? Yep, that's on you [and here Rust wins!].
And don't even think about safety nets like preventing data races or dangling reference errors, It's a bit of a rollercoaster, but hey, sometimes you need that freedom.

2- Rust

Now let's me talk a bit about Rust in this contest.
It's like C's younger sibling who's always preaching about safety and memory management :)) But you know what? It's got some cool tricks up its sleeve.
Here's Rust counting to 500M, I have used cargo run --release [which was way faster than with rustc command]

use std::time::{Instant};

fn main() {
    let start_time = Instant::now();

    let mut count: u64 = 0;
    let target: u64 = 500_000_000;

    while count < target {
        count += 1;
    }

    let elapsed_time = start_time.elapsed().as_secs_f64();

    println!("Counting to {} took {} seconds.", target, elapsed_time);
}
Enter fullscreen mode Exit fullscreen mode

Rust might seem a bit intimidating at first, but it's got some serious game. With features like ownership and lifetimes [tutorials made, but not yet uploaded on the channel], it keeps you from shooting yourself in the foot with null pointers and data races.
Also the result of the Rust speed test was shocking !

Finding Your Groove

So, which one should you go for? Well, it depends on what floats your boat. If you're all about tradition and doing things your way, C might be your jam. But if you're ready to embrace the future and prioritize safety and reliability, Rust might just be your new bestie.

At the end of the day, it's not about which language is better. It's about finding the right tool for the job and being open to new ideas and perspectives. So, whether you're rocking C, Rust, or something entirely different, remember that we're all in this together.

Your Feedback Matters

I wanna hear from you, folks!
What's your take on C and Rust?
Any cool stories or experiences to share?
Drop 'em in the comments below, and let's keep this conversation rolling.

Thanks for reading this article.
Until next time, happy coding! 🚀

clang Article's
27 articles in total
Favicon
Tester c'est tricher, compiler c'est douter
Favicon
Pointers in Modern C
Favicon
Creating a Robust Logging System in C
Favicon
The unspoken question: "Why do pointers exist?"
Favicon
Pointers : what are they pointing to?
Favicon
Setting up linters in Gitlab CI for C++ and Groovy / Jenkins code
Favicon
SORRY, RUST & DEVS !
Favicon
Cycle don&amp;#39;t want to write to the array
Favicon
cách xử lý lỗi không chạy được code C++ trong Code::Blocks "Tried to run compiler enumerable `C:\MinGW/bin/gcc.exe` but failed"
Favicon
Building an XDP eBPF Program with C and Golang: A Step-by-Step Guide
Favicon
Should I Learn Math First, Then Rust or C, or Can I Learn Mathematics and Rust, C Simultaneously?
Favicon
The C Programming Language by Brian W. Kernighan & Dennis M. Ritchie.
Favicon
The C Programming Language by Brian W. Kernighan & Dennis M. Ritchie.
Favicon
Dynamic Linker Hijacking Experiments - Evasive Techniques (Part 1)
Favicon
How To Include ‘bits/stdc++.h’ Header File With Clang Compiler on macOS
Favicon
How many asterisks can be put?
Favicon
A common pitfall when using sizeof() with pointers
Favicon
Platform detection in C&C++
Favicon
Lint Lint Boom
Favicon
Behind C++ Lambda Functions
Favicon
C++ Levitation: Looking for contributors
Favicon
Type qualifier: register, volatile and restrict - C Programming
Favicon
Configuring Oni as a C / C++ IDE on Ubuntu 18.04
Favicon
Use `bool` in C program
Favicon
Clang vs GCC
Favicon
Working on Object Lifetime Analysis for C++
Favicon
Writing safer C with Clang address sanitizer

Featured ones: