fix benchmarks
This commit is contained in:
parent
ef726591f8
commit
a9ea4d0127
3 changed files with 14 additions and 9 deletions
|
@ -61,12 +61,14 @@ impl MutableSet<uint> for BitvSet {
|
|||
|
||||
impl Results {
|
||||
pub fn bench_int<T:MutableSet<uint>,
|
||||
R: rand::Rng>(
|
||||
R:rand::Rng,
|
||||
F:FnMut() -> T>(
|
||||
&mut self,
|
||||
rng: &mut R,
|
||||
num_keys: uint,
|
||||
rand_cap: uint,
|
||||
f: || -> T) { {
|
||||
mut f: F) {
|
||||
{
|
||||
let mut set = f();
|
||||
timed(&mut self.sequential_ints, || {
|
||||
for i in range(0u, num_keys) {
|
||||
|
@ -103,11 +105,12 @@ impl Results {
|
|||
}
|
||||
|
||||
pub fn bench_str<T:MutableSet<String>,
|
||||
R:rand::Rng>(
|
||||
R:rand::Rng,
|
||||
F:FnMut() -> T>(
|
||||
&mut self,
|
||||
rng: &mut R,
|
||||
num_keys: uint,
|
||||
f: || -> T) {
|
||||
mut f: F) {
|
||||
{
|
||||
let mut set = f();
|
||||
timed(&mut self.sequential_strings, || {
|
||||
|
|
|
@ -94,7 +94,9 @@ fn update_freq(mm: &mut HashMap<Vec<u8> , uint>, key: &[u8]) {
|
|||
// given a Vec<u8>, for each window call a function
|
||||
// i.e., for "hello" and windows of size four,
|
||||
// run it("hell") and it("ello"), then return "llo"
|
||||
fn windows_with_carry(bb: &[u8], nn: uint, it: |window: &[u8]|) -> Vec<u8> {
|
||||
fn windows_with_carry<F>(bb: &[u8], nn: uint, mut it: F) -> Vec<u8> where
|
||||
F: FnMut(&[u8]),
|
||||
{
|
||||
let mut ii = 0u;
|
||||
|
||||
let len = bb.len();
|
||||
|
|
|
@ -53,14 +53,14 @@ use std::thread::Thread;
|
|||
|
||||
// returns an infinite iterator of repeated applications of f to x,
|
||||
// i.e. [x, f(x), f(f(x)), ...], as haskell iterate function.
|
||||
fn iterate<'a, T>(x: T, f: |&T|: 'a -> T) -> Iterate<'a, T> {
|
||||
fn iterate<T, F>(x: T, f: F) -> Iterate<T, F> where F: FnMut(&T) -> T {
|
||||
Iterate {f: f, next: x}
|
||||
}
|
||||
struct Iterate<'a, T> {
|
||||
f: |&T|: 'a -> T,
|
||||
struct Iterate<T, F> where F: FnMut(&T) -> T {
|
||||
f: F,
|
||||
next: T
|
||||
}
|
||||
impl<'a, T> Iterator for Iterate<'a, T> {
|
||||
impl<T, F> Iterator for Iterate<T, F> where F: FnMut(&T) -> T {
|
||||
type Item = T;
|
||||
|
||||
fn next(&mut self) -> Option<T> {
|
||||
|
|
Loading…
Add table
Reference in a new issue