]>
git.proxmox.com Git - rustc.git/blob - src/test/bench/std-smallintmap.rs
1 // Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 // Microbenchmark for the smallintmap library
13 #![feature(vecmap, duration, duration_span)]
15 use std
::collections
::VecMap
;
17 use std
::time
::Duration
;
19 fn append_sequential(min
: usize, max
: usize, map
: &mut VecMap
<usize>) {
21 map
.insert(i
, i
+ 22);
25 fn check_sequential(min
: usize, max
: usize, map
: &VecMap
<usize>) {
27 assert_eq
!(map
[i
], i
+ 22);
32 let args
= env
::args();
33 let args
= if env
::var_os("RUST_BENCH").is_some() {
34 vec
!("".to_string(), "100000".to_string(), "100".to_string())
35 } else if args
.len() <= 1 {
36 vec
!("".to_string(), "10000".to_string(), "50".to_string())
40 let max
= args
[1].parse
::<usize>().unwrap();
41 let rep
= args
[2].parse
::<usize>().unwrap();
43 let mut checkf
= Duration
::new(0, 0);
44 let mut appendf
= Duration
::new(0, 0);
47 let mut map
= VecMap
::new();
48 let d1
= Duration
::span(|| append_sequential(0, max
, &mut map
));
49 let d2
= Duration
::span(|| check_sequential(0, max
, &map
));
52 appendf
= appendf
+ d1
;
55 let maxf
= max
as f64;
57 println
!("insert(): {} seconds\n", checkf
);
58 println
!(" : {} op/s\n", maxf
/ checkf
.secs() as f64);
59 println
!("get() : {} seconds\n", appendf
);
60 println
!(" : {} op/s\n", maxf
/ appendf
.secs() as f64);