Fix benches

This commit is contained in:
Jorge Aparicio 2014-12-08 08:35:34 -05:00
parent cdbb3ca9b7
commit 2160427900
3 changed files with 14 additions and 9 deletions

View file

@ -8,13 +8,15 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
#![feature(unboxed_closures)]
use std::collections::{TrieMap, TreeMap, HashMap, HashSet}; use std::collections::{TrieMap, TreeMap, HashMap, HashSet};
use std::os; use std::os;
use std::rand::{Rng, IsaacRng, SeedableRng}; use std::rand::{Rng, IsaacRng, SeedableRng};
use std::time::Duration; use std::time::Duration;
use std::uint; use std::uint;
fn timed(label: &str, f: ||) { fn timed<F>(label: &str, f: F) where F: FnMut() {
println!(" {}: {}", label, Duration::span(f)); println!(" {}: {}", label, Duration::span(f));
} }

View file

@ -10,6 +10,8 @@
// ignore-pretty very bad with line comments // ignore-pretty very bad with line comments
#![feature(unboxed_closures)]
extern crate collections; extern crate collections;
extern crate rand; extern crate rand;
@ -31,7 +33,7 @@ struct Results {
delete_strings: Duration, delete_strings: Duration,
} }
fn timed(result: &mut Duration, op: ||) { fn timed<F>(result: &mut Duration, op: F) where F: FnOnce() {
*result = Duration::span(op); *result = Duration::span(op);
} }
@ -66,7 +68,7 @@ impl Results {
rand_cap: uint, rand_cap: uint,
f: || -> T) { { f: || -> T) { {
let mut set = f(); let mut set = f();
timed(&mut self.sequential_ints, || { timed(&mut self.sequential_ints, move || {
for i in range(0u, num_keys) { for i in range(0u, num_keys) {
set.insert(i); set.insert(i);
} }
@ -79,7 +81,7 @@ impl Results {
{ {
let mut set = f(); let mut set = f();
timed(&mut self.random_ints, || { timed(&mut self.random_ints, move || {
for _ in range(0, num_keys) { for _ in range(0, num_keys) {
set.insert(rng.gen::<uint>() % rand_cap); set.insert(rng.gen::<uint>() % rand_cap);
} }
@ -92,7 +94,7 @@ impl Results {
set.insert(i); set.insert(i);
} }
timed(&mut self.delete_ints, || { timed(&mut self.delete_ints, move || {
for i in range(0u, num_keys) { for i in range(0u, num_keys) {
assert!(set.remove(&i)); assert!(set.remove(&i));
} }
@ -108,7 +110,7 @@ impl Results {
f: || -> T) { f: || -> T) {
{ {
let mut set = f(); let mut set = f();
timed(&mut self.sequential_strings, || { timed(&mut self.sequential_strings, move || {
for i in range(0u, num_keys) { for i in range(0u, num_keys) {
set.insert(i.to_string()); set.insert(i.to_string());
} }
@ -121,7 +123,7 @@ impl Results {
{ {
let mut set = f(); let mut set = f();
timed(&mut self.random_strings, || { timed(&mut self.random_strings, move || {
for _ in range(0, num_keys) { for _ in range(0, num_keys) {
let s = rng.gen::<uint>().to_string(); let s = rng.gen::<uint>().to_string();
set.insert(s); set.insert(s);
@ -134,7 +136,7 @@ impl Results {
for i in range(0u, num_keys) { for i in range(0u, num_keys) {
set.insert(i.to_string()); set.insert(i.to_string());
} }
timed(&mut self.delete_strings, || { timed(&mut self.delete_strings, move || {
for i in range(0u, num_keys) { for i in range(0u, num_keys) {
assert!(set.remove(&i.to_string())); assert!(set.remove(&i.to_string()));
} }

View file

@ -12,6 +12,7 @@
// Microbenchmarks for various functions in std and extra // Microbenchmarks for various functions in std and extra
#![feature(macro_rules)] #![feature(macro_rules)]
#![feature(unboxed_closures)]
use std::io::File; use std::io::File;
use std::mem::swap; use std::mem::swap;
@ -41,7 +42,7 @@ fn main() {
bench!(is_utf8_multibyte); bench!(is_utf8_multibyte);
} }
fn maybe_run_test(argv: &[String], name: String, test: ||) { fn maybe_run_test<F>(argv: &[String], name: String, test: F) where F: FnOnce() {
let mut run_test = false; let mut run_test = false;
if os::getenv("RUST_BENCH").is_some() { if os::getenv("RUST_BENCH").is_some() {