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.
|
|
|
|
|
2013-01-31 18:07:08 -06:00
|
|
|
// Microbenchmark for the smallintmap library
|
2012-05-15 08:00:55 -05:00
|
|
|
|
2014-10-30 20:25:08 -05:00
|
|
|
use std::collections::VecMap;
|
2013-05-24 21:35:29 -05:00
|
|
|
use std::os;
|
2014-12-22 11:04:23 -06:00
|
|
|
use std::str::from_str;
|
2014-11-10 14:27:56 -06:00
|
|
|
use std::time::Duration;
|
2013-05-24 21:35:29 -05:00
|
|
|
use std::uint;
|
2012-05-15 08:00:55 -05:00
|
|
|
|
2014-10-30 20:25:08 -05:00
|
|
|
fn append_sequential(min: uint, max: uint, map: &mut VecMap<uint>) {
|
2013-08-03 11:45:23 -05:00
|
|
|
for i in range(min, max) {
|
2012-05-15 08:00:55 -05:00
|
|
|
map.insert(i, i + 22u);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-30 20:25:08 -05:00
|
|
|
fn check_sequential(min: uint, max: uint, map: &VecMap<uint>) {
|
2013-08-03 11:45:23 -05:00
|
|
|
for i in range(min, max) {
|
2014-10-15 01:05:01 -05:00
|
|
|
assert_eq!(map[i], i + 22u);
|
2012-05-15 08:00:55 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-03 21:16:27 -05:00
|
|
|
fn main() {
|
|
|
|
let args = os::args();
|
2013-07-17 14:31:20 -05:00
|
|
|
let args = if os::getenv("RUST_BENCH").is_some() {
|
2014-05-25 05:10:11 -05:00
|
|
|
vec!("".to_string(), "100000".to_string(), "100".to_string())
|
2012-05-24 00:53:50 -05:00
|
|
|
} else if args.len() <= 1u {
|
2014-05-25 05:10:11 -05:00
|
|
|
vec!("".to_string(), "10000".to_string(), "50".to_string())
|
2012-05-24 00:53:50 -05:00
|
|
|
} else {
|
2014-09-14 22:27:36 -05:00
|
|
|
args.into_iter().collect()
|
2012-05-24 00:53:50 -05:00
|
|
|
};
|
2014-10-15 01:05:01 -05:00
|
|
|
let max = from_str::<uint>(args[1].as_slice()).unwrap();
|
|
|
|
let rep = from_str::<uint>(args[2].as_slice()).unwrap();
|
2012-05-15 08:00:55 -05:00
|
|
|
|
2014-11-10 14:27:56 -06:00
|
|
|
let mut checkf = Duration::seconds(0);
|
|
|
|
let mut appendf = Duration::seconds(0);
|
2012-05-15 08:00:55 -05:00
|
|
|
|
2013-08-03 11:45:23 -05:00
|
|
|
for _ in range(0u, rep) {
|
2014-10-30 20:25:08 -05:00
|
|
|
let mut map = VecMap::new();
|
2014-11-10 14:27:56 -06:00
|
|
|
let d1 = Duration::span(|| append_sequential(0u, max, &mut map));
|
|
|
|
let d2 = Duration::span(|| check_sequential(0u, max, &map));
|
2012-05-15 08:00:55 -05:00
|
|
|
|
2014-11-10 14:27:56 -06:00
|
|
|
checkf = checkf + d2;
|
|
|
|
appendf = appendf + d1;
|
2012-05-15 08:00:55 -05:00
|
|
|
}
|
|
|
|
|
2013-09-26 01:26:09 -05:00
|
|
|
let maxf = max as f64;
|
2012-05-15 08:00:55 -05:00
|
|
|
|
2014-10-14 20:07:11 -05:00
|
|
|
println!("insert(): {} seconds\n", checkf);
|
2014-11-10 14:27:56 -06:00
|
|
|
println!(" : {} op/ms\n", maxf / checkf.num_milliseconds() as f64);
|
2014-10-14 20:07:11 -05:00
|
|
|
println!("get() : {} seconds\n", appendf);
|
2014-11-10 14:27:56 -06:00
|
|
|
println!(" : {} op/ms\n", maxf / appendf.num_milliseconds() as f64);
|
2012-06-28 19:31:05 -05:00
|
|
|
}
|