2012-05-09 19:30:31 -05:00
|
|
|
// A raw test of vector appending performance.
|
|
|
|
|
|
|
|
use std;
|
|
|
|
import dvec::{dvec, extensions};
|
|
|
|
import io::writer_util;
|
|
|
|
|
|
|
|
fn collect_raw(num: uint) -> [uint] {
|
|
|
|
let mut result = [];
|
2012-05-26 02:32:08 -05:00
|
|
|
for uint::range(0u, num) { |i|
|
2012-05-09 19:30:31 -05:00
|
|
|
result += [i];
|
2012-06-13 18:14:01 -05:00
|
|
|
//vec::push(result, i);
|
|
|
|
//result = vec::append(result, [i]);
|
2012-05-09 19:30:31 -05:00
|
|
|
}
|
|
|
|
ret result;
|
|
|
|
}
|
|
|
|
|
|
|
|
fn collect_dvec(num: uint) -> [mut uint] {
|
|
|
|
let result = dvec();
|
2012-05-26 02:32:08 -05:00
|
|
|
for uint::range(0u, num) { |i|
|
2012-05-09 19:30:31 -05:00
|
|
|
result.push(i);
|
|
|
|
}
|
|
|
|
ret dvec::unwrap(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main(args: [str]) {
|
2012-05-24 00:53:50 -05:00
|
|
|
let args = if os::getenv("RUST_BENCH").is_some() {
|
2012-05-26 17:59:46 -05:00
|
|
|
["", "50000000"]
|
2012-05-24 00:53:50 -05:00
|
|
|
} else if args.len() <= 1u {
|
|
|
|
["", "100000"]
|
|
|
|
} else {
|
|
|
|
args
|
|
|
|
};
|
2012-05-09 19:30:31 -05:00
|
|
|
let max = uint::from_str(args[1]).get();
|
|
|
|
let start = std::time::precise_time_s();
|
2012-05-12 21:09:09 -05:00
|
|
|
let raw_v = collect_raw(max);
|
2012-05-09 19:30:31 -05:00
|
|
|
let mid = std::time::precise_time_s();
|
2012-05-12 21:09:09 -05:00
|
|
|
let dvec_v = collect_dvec(max);
|
2012-05-09 19:30:31 -05:00
|
|
|
let end = std::time::precise_time_s();
|
|
|
|
|
2012-05-12 21:09:09 -05:00
|
|
|
// check each vector
|
|
|
|
assert raw_v.len() == max;
|
|
|
|
for raw_v.eachi { |i, v| assert i == v; }
|
|
|
|
assert dvec_v.len() == max;
|
|
|
|
for dvec_v.eachi { |i, v| assert i == v; }
|
|
|
|
|
2012-05-09 19:30:31 -05:00
|
|
|
let raw = mid - start;
|
|
|
|
let dvec = end - mid;
|
2012-06-13 18:14:01 -05:00
|
|
|
|
2012-05-09 19:30:31 -05:00
|
|
|
let maxf = max as float;
|
|
|
|
let rawf = raw as float;
|
|
|
|
let dvecf = dvec as float;
|
2012-06-13 18:14:01 -05:00
|
|
|
|
2012-05-09 19:30:31 -05:00
|
|
|
io::stdout().write_str(#fmt("Raw : %? seconds\n", raw));
|
|
|
|
io::stdout().write_str(#fmt(" : %f op/sec\n", maxf/rawf));
|
|
|
|
io::stdout().write_str(#fmt("\n"));
|
|
|
|
io::stdout().write_str(#fmt("Dvec : %? seconds\n", dvec));
|
|
|
|
io::stdout().write_str(#fmt(" : %f op/sec\n", maxf/dvecf));
|
|
|
|
io::stdout().write_str(#fmt("\n"));
|
2012-06-13 18:14:01 -05:00
|
|
|
|
2012-05-09 19:30:31 -05:00
|
|
|
if dvec < raw {
|
|
|
|
io::stdout().write_str(#fmt("Dvec is %f%% faster than raw\n",
|
|
|
|
(rawf - dvecf) / rawf * 100.0));
|
|
|
|
} else {
|
|
|
|
io::stdout().write_str(#fmt("Raw is %f%% faster than dvec\n",
|
|
|
|
(dvecf - rawf) / dvecf * 100.0));
|
|
|
|
}
|
|
|
|
}
|