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
|
|
|
|
2012-09-11 19:46:20 -05:00
|
|
|
extern mod std;
|
2013-01-31 18:07:08 -06:00
|
|
|
use std::smallintmap::SmallIntMap;
|
2013-03-01 17:55:31 -06:00
|
|
|
use core::io::WriterUtil;
|
2012-05-15 08:00:55 -05:00
|
|
|
|
2013-01-31 18:07:08 -06:00
|
|
|
fn append_sequential(min: uint, max: uint, map: &mut SmallIntMap<uint>) {
|
2012-06-30 18:19:07 -05:00
|
|
|
for uint::range(min, max) |i| {
|
2012-05-15 08:00:55 -05:00
|
|
|
map.insert(i, i + 22u);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-31 18:07:08 -06:00
|
|
|
fn check_sequential(min: uint, max: uint, map: &SmallIntMap<uint>) {
|
2012-06-30 18:19:07 -05:00
|
|
|
for uint::range(min, max) |i| {
|
2013-03-28 20:39:09 -05:00
|
|
|
assert!(*map.get(&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();
|
2012-07-14 00:57:48 -05:00
|
|
|
let args = if os::getenv(~"RUST_BENCH").is_some() {
|
|
|
|
~[~"", ~"100000", ~"100"]
|
2012-05-24 00:53:50 -05:00
|
|
|
} else if args.len() <= 1u {
|
2012-07-14 00:57:48 -05:00
|
|
|
~[~"", ~"10000", ~"50"]
|
2012-05-24 00:53:50 -05:00
|
|
|
} else {
|
|
|
|
args
|
|
|
|
};
|
2012-05-15 08:00:55 -05:00
|
|
|
let max = uint::from_str(args[1]).get();
|
|
|
|
let rep = uint::from_str(args[2]).get();
|
|
|
|
|
|
|
|
let mut checkf = 0.0;
|
|
|
|
let mut appendf = 0.0;
|
|
|
|
|
2012-06-30 18:19:07 -05:00
|
|
|
for uint::range(0u, rep) |_r| {
|
2013-01-31 18:07:08 -06:00
|
|
|
let mut map = SmallIntMap::new();
|
2012-05-15 08:00:55 -05:00
|
|
|
let start = std::time::precise_time_s();
|
2013-01-31 18:07:08 -06:00
|
|
|
append_sequential(0u, max, &mut map);
|
2012-05-15 08:00:55 -05:00
|
|
|
let mid = std::time::precise_time_s();
|
2013-01-31 18:07:08 -06:00
|
|
|
check_sequential(0u, max, &map);
|
2012-05-15 08:00:55 -05:00
|
|
|
let end = std::time::precise_time_s();
|
|
|
|
|
|
|
|
checkf += (end - mid) as float;
|
|
|
|
appendf += (mid - start) as float;
|
|
|
|
}
|
|
|
|
|
|
|
|
let maxf = max as float;
|
|
|
|
|
2012-08-22 19:24:52 -05:00
|
|
|
io::stdout().write_str(fmt!("insert(): %? seconds\n", checkf));
|
|
|
|
io::stdout().write_str(fmt!(" : %f op/sec\n", maxf/checkf));
|
|
|
|
io::stdout().write_str(fmt!("get() : %? seconds\n", appendf));
|
|
|
|
io::stdout().write_str(fmt!(" : %f op/sec\n", maxf/appendf));
|
2012-06-28 19:31:05 -05:00
|
|
|
}
|