Hi Felix,

Thanks for your response. That is an interest observation you made about
the println functon.

Upon playing with the code a bit more, I noticed that the strange behaviour
seems to be limited to the function "second". The distinguishing feature of
this function is that it involves a nested function.

I have rewritten the codes to only involve a single function in each source
file (in order to illustrate this better) & the source and results are
below (to call the functions twice just uncomment the last few lines I have
commented out in each program) :

firstAndFirst.rs
1)Call "first" once : 4.5s
2)Call "first" twice : 9.4s

secondAndSecond.rs (nested function call_
1)Call "second" once : 9.5s
2)Call "second" twice : 43.8s (--> I would have expected this to be 19s <--)

*********************************************************************************
*********************************************************************************
//firstAndFirst.rs
static g_r: float = 3.569956;
static g_x0:float = 0.53;

fn first(n: i64, x0 : float, r: float) -> float {
    let mut x = x0;
    let mut i = 0i64;
    loop {
        x = r*x*(1.-x);
        i += 1;
        if i == n { break }
    }
    x
}

fn main(){
    let l = 400000000i64;

    let result = first(l,g_x0,g_r);
    io::println(float::to_str(result));

    //let result2 = first(l,g_x0,g_r);
    //io::println(float::to_str(result2));
}
*********************************************************************************
*********************************************************************************
//secondAndSecond.rs
static g_r: float = 3.569956;
static g_x0:float = 0.53;

fn second(n: i64, x0 : float, r: float) -> float {

    fn calc(x : float, r: float) -> float {
        let mut xm = x;
        xm = r*xm*(1.-xm);
        xm
    }

    let mut x = x0;
    let mut i = 0i64;
    loop {
        x = calc(x,r);
        i += 1;
        if i == n { break }
    }
    x

}

fn main(){
    let l = 400000000i64;

    let result = second(l,g_x0,g_r);
    io::println(float::to_str(result));

    //let result2 = second(l,g_x0,g_r);
    //io::println(float::to_str(result2));
}
*********************************************************************************
*********************************************************************************
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to