2012-12-10 19:32:48 -06:00
|
|
|
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2012-05-09 19:30:31 -05:00
|
|
|
// A raw test of vector appending performance.
|
|
|
|
|
2012-09-11 19:46:20 -05:00
|
|
|
extern mod std;
|
2013-03-01 17:55:31 -06:00
|
|
|
use core::dvec::DVec;
|
|
|
|
use core::io::WriterUtil;
|
2012-05-09 19:30:31 -05:00
|
|
|
|
2012-06-29 18:26:56 -05:00
|
|
|
fn collect_raw(num: uint) -> ~[uint] {
|
|
|
|
let mut result = ~[];
|
2012-06-30 18:19:07 -05:00
|
|
|
for uint::range(0u, num) |i| {
|
2012-09-26 19:33:34 -05:00
|
|
|
result.push(i);
|
2012-05-09 19:30:31 -05:00
|
|
|
}
|
2012-08-01 19:30:05 -05:00
|
|
|
return result;
|
2012-05-09 19:30:31 -05:00
|
|
|
}
|
|
|
|
|
2012-09-12 12:38:17 -05:00
|
|
|
fn collect_dvec(num: uint) -> ~[uint] {
|
2012-08-27 16:22:25 -05:00
|
|
|
let result = DVec();
|
2012-06-30 18:19:07 -05:00
|
|
|
for uint::range(0u, num) |i| {
|
2012-05-09 19:30:31 -05:00
|
|
|
result.push(i);
|
|
|
|
}
|
2013-02-15 04:44:18 -06:00
|
|
|
return dvec::unwrap(result);
|
2012-05-09 19:30:31 -05:00
|
|
|
}
|
|
|
|
|
2012-10-03 21:16:27 -05:00
|
|
|
fn main() {
|
|
|
|
let args = os::args();
|
2012-07-14 00:57:48 -05:00
|
|
|
let args = if os::getenv(~"RUST_BENCH").is_some() {
|
|
|
|
~[~"", ~"50000000"]
|
2012-05-24 00:53:50 -05:00
|
|
|
} else if args.len() <= 1u {
|
2012-07-14 00:57:48 -05:00
|
|
|
~[~"", ~"100000"]
|
2012-05-24 00:53:50 -05:00
|
|
|
} 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;
|
2012-09-21 20:43:30 -05:00
|
|
|
for raw_v.eachi |i, v| { assert i == *v; }
|
2012-05-12 21:09:09 -05:00
|
|
|
assert dvec_v.len() == max;
|
2012-09-21 20:43:30 -05:00
|
|
|
for dvec_v.eachi |i, v| { assert i == *v; }
|
2012-05-12 21:09:09 -05:00
|
|
|
|
2012-05-09 19:30:31 -05:00
|
|
|
let raw = mid - start;
|
|
|
|
let dvec = end - mid;
|
2012-09-12 12:38:17 -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-08-22 19:24:52 -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 {
|
2012-08-22 19:24:52 -05:00
|
|
|
io::stdout().write_str(fmt!("Dvec is %f%% faster than raw\n",
|
|
|
|
(rawf - dvecf) / rawf * 100.0));
|
2012-05-09 19:30:31 -05:00
|
|
|
} else {
|
2012-08-22 19:24:52 -05:00
|
|
|
io::stdout().write_str(fmt!("Raw is %f%% faster than dvec\n",
|
|
|
|
(dvecf - rawf) / dvecf * 100.0));
|
2012-05-09 19:30:31 -05:00
|
|
|
}
|
|
|
|
}
|