Artella (cc'ing rust-dev)-
It is an interesting phenomenon that you note.
I think it is arising from the fact that you have *two* expressions of the form
io::println(float::to_str(...)) in the main fn from firstAndSecond.rs, while
each of the other two rs files have only one expression of the form
io::println(float::to_str(..)).
In fact, when I revised your fn main from firstAndSecond.rs to look like this:
fn main(){
let l = 400000000i64;
let result = first(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));
io::println(fmt!("%s\n%s", float::to_str(result),
float::to_str(result2)));
}
then the running time dropped back down to something more closely approximating
the sum of first and second:
% time ./first
0.507920831295682972950089606456458568572998046875
real 0m1.795s
user 0m1.791s
sys 0m0.003s
% time ./second
0.507920831295682972950089606456458568572998046875
real 0m5.150s
user 0m5.144s
sys 0m0.005s
% time ./firstAndSecond
0.507920831295682972950089606456458568572998046875
0.507920831295682972950089606456458568572998046875
real 0m6.941s
user 0m6.933s
sys 0m0.007s
Of course, this is not what you wrote, since presumably the user would like to
get feed back about the first step completing without waiting for the longer
second step.
I am not sure why fusing your two io::println calls into one seems to resolve
this issue. (There are many potential places to look, though; such as how
expensive flushing the port might be? Or whether there is some state that
needs to be cleaned up on the second call to io::println? But really, I am
just guessing.)
Anyway, I just thought I'd share what little I had discovered after playing
with your code.
Cheers,
-Felix
----- Original Message -----
From: "Artella Coding" <[email protected]>
To: [email protected]
Sent: Sunday, April 14, 2013 7:06:56 PM
Subject: [rust-dev] Non additive execution time scaling
Hi, suppose I have :
1) first.rs calls function "first"
2) second.rs calls function "second"
3)firstAndSecond.rs calls function "first" followed by function "second"
Then I would expect (ignoring "startup" times) that:
TimeToRun( firstAndSecond.rs) = TimeToRun( first.rs ) + TimeToRun( second.rs )
However instead I find that :
TimeToRun( firstAndSecond.rs) > TimeToRun( first.rs ) + TimeToRun( second.rs )
Specifically :
TimeToRun( first.rs ) = real 0m2.631s
TimeToRun( second.rs ) = real 0m5.739s
TimeToRun( firstAndSecond.rs) = real 0m23.856s
I cannot quite work out why this might be the case (and I dont think it is to
do with startup times). Note I compile the programs as follows :
rustc first.rs
rustc second.rs
rustc firstAndSecond.rs
Note that when you profile the programs, "firstAndSecond" looks a bit strange
in that there are library calls which are absent when one profiles first or
second.
The programs are given below :
********************************************************************************
********************************************************************************
********************************************************************************
********************************************************************************
// first.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 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 = first(l,g_x0,g_r);
io::println(float::to_str(result));
}
********************************************************************************
********************************************************************************
********************************************************************************
********************************************************************************
// second.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 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));
}
********************************************************************************
********************************************************************************
********************************************************************************
********************************************************************************
//firstAndSecond.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 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 = first(l,g_x0,g_r);
io::println(float::to_str(result));
let result = second(l,g_x0,g_r);
io::println(float::to_str(result));
}
********************************************************************************
********************************************************************************
********************************************************************************
********************************************************************************
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev