mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-03 20:23:59 +00:00
perf: improved the core-std benchmark
This commit is contained in:
parent
a08281616f
commit
ccd2394ff9
@ -326,7 +326,7 @@ Convert a set into a vector.
|
||||
fn vec_from_set<T: copy>(s: set<T>) -> [T]/~ {
|
||||
let mut v = []/~;
|
||||
s.each_key() {|k|
|
||||
v += [k]/~;
|
||||
vec::push(v, k);
|
||||
true
|
||||
};
|
||||
v
|
||||
|
@ -3,17 +3,25 @@
|
||||
use std;
|
||||
|
||||
import std::time::precise_time_s;
|
||||
import std::map;
|
||||
import std::map::{map, hashmap};
|
||||
|
||||
import io::{reader, reader_util};
|
||||
|
||||
fn main() {
|
||||
fn main(argv: [str]/~) {
|
||||
#macro[
|
||||
[#bench[id],
|
||||
run_test(#stringify(id), id)]
|
||||
if tests.len() == 0 || vec::contains(tests, #stringify(id)) {
|
||||
run_test(#stringify(id), id);
|
||||
}
|
||||
]
|
||||
];
|
||||
|
||||
let tests = vec::view(argv, 1, argv.len());
|
||||
|
||||
#bench[shift_push];
|
||||
#bench[read_line];
|
||||
#bench[str_set];
|
||||
}
|
||||
|
||||
fn run_test(name: str, test: fn()) {
|
||||
@ -46,3 +54,21 @@ fn read_line() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn str_set() {
|
||||
let r = rand::rng();
|
||||
|
||||
let s = map::hashmap(str::hash, str::eq);
|
||||
|
||||
for int::range(0, 1000) {|_i|
|
||||
map::set_add(s, r.gen_str(10));
|
||||
}
|
||||
|
||||
let mut found = 0;
|
||||
for int::range(0, 1000) {|_i|
|
||||
alt s.find(r.gen_str(10)) {
|
||||
some(_) { found += 1; }
|
||||
none { }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user