perf: improved the core-std benchmark
This commit is contained in:
parent
a08281616f
commit
ccd2394ff9
2 changed files with 29 additions and 3 deletions
|
@ -326,7 +326,7 @@ Convert a set into a vector.
|
||||||
fn vec_from_set<T: copy>(s: set<T>) -> [T]/~ {
|
fn vec_from_set<T: copy>(s: set<T>) -> [T]/~ {
|
||||||
let mut v = []/~;
|
let mut v = []/~;
|
||||||
s.each_key() {|k|
|
s.each_key() {|k|
|
||||||
v += [k]/~;
|
vec::push(v, k);
|
||||||
true
|
true
|
||||||
};
|
};
|
||||||
v
|
v
|
||||||
|
|
|
@ -3,17 +3,25 @@
|
||||||
use std;
|
use std;
|
||||||
|
|
||||||
import std::time::precise_time_s;
|
import std::time::precise_time_s;
|
||||||
|
import std::map;
|
||||||
|
import std::map::{map, hashmap};
|
||||||
|
|
||||||
import io::{reader, reader_util};
|
import io::{reader, reader_util};
|
||||||
|
|
||||||
fn main() {
|
fn main(argv: [str]/~) {
|
||||||
#macro[
|
#macro[
|
||||||
[#bench[id],
|
[#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[shift_push];
|
||||||
#bench[read_line];
|
#bench[read_line];
|
||||||
|
#bench[str_set];
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_test(name: str, test: fn()) {
|
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…
Add table
Add a link
Reference in a new issue