Return value and unuse it

If I use return word in end of function can low performance? Or no difference between using return or direct put my variable?

I presume you are asking about the difference between this:

pub fn square(num: i32) -> i32 {
    let result = num * num;
    result
}

and this:

pub fn square(num: i32) -> i32 {
    let result = num * num;
    return result;
}

If you compile both of those you will find they produce exactly the same executable instructions.

As can be seen on godbolt here: Compiler Explorer

So, no difference in performance.

1 Like

Thank you.