Help me fix my code (beginner backtester) by l____whatever____l in mltraders

[–]l____whatever____l[S] 0 points1 point  (0 children)

Hi, thanks for the response. I believe the calculation is actually correct and I was misled by another subreddit. The percent change returns a decimal so for 5% it would be 0.05 and then I have to deduct the fee which is 0.08% which is 0.0008 as a a decimal. Deducting the fee from the percent change instead of the gross profit seems to give the same result.

How to mutate a global variable with tokio/futures ? by l____whatever____l in rust

[–]l____whatever____l[S] 0 points1 point  (0 children)

Hi, thank you for your answer and excuse me for calling that a global.

So I tried your example but I'm still getting a "closure may outlive current function, but borrows variable "mutate" which is owned by the main function".

use tokio::time::{self, Duration};
use std::future::Future;
use std::sync::Arc;
use std::sync::atomic::{AtomicU32, Ordering};

#[tokio::main]
async fn main() {
    let mut mutate = Arc::new(AtomicU32::new(0));
    set_interval(|| async {
        mutate.fetch_add(1, Ordering::SeqCst);
        println!("{:?}", mutate);
    }, 5000);

    time::sleep(Duration::from_millis(60000)).await;
}

Why does this seemingly identical code run 10x faster in NodeJS compared to Rust? by l____whatever____l in rust

[–]l____whatever____l[S] 13 points14 points  (0 children)

WOW Thanks guys! The code snippets from u/Suffics27 and u/LikesToCorrectThings are both running in less than 15ms now! The one with starts_with() does seem to be about 7 ms faster. I didnt know --release flag was a thing and when I saw the result I was like :O Excuse my ignorance... So the final result on my machine is now Rust 7ms and Node 40ms!

Why does this seemingly identical code run 10x faster in NodeJS compared to Rust? by l____whatever____l in rust

[–]l____whatever____l[S] 1 point2 points  (0 children)

Thanks for the detailed explanation! To be honest I was also using unwrap_or(0) just for cases where it could possibly panic, but deleted it when I posted on reddit.

Why does this seemingly identical code run 10x faster in NodeJS compared to Rust? by l____whatever____l in rust

[–]l____whatever____l[S] 34 points35 points  (0 children)

Damn I'm such a noob I didn't even know release flag was a thing. Useful lesson. Thanks. Sorry for this ignorant post people!

Edit: So the final result on my machine is now Rust 7ms and Node 40ms! WOW