Skip to content

Commit 7393fde

Browse files
committed
auto merge of #4515 : graydon/rust/bench-harness, r=graydon
This is scaffolding for the new #[bench] attribute for marking unit tests as benchmarks. They are run with the --bench flag that the test runner now accepts. The runner automatically calibrates a test loop to an appropriate count to get a good per-iteration measurement.
2 parents d06e6e7 + e5aa399 commit 7393fde

File tree

13 files changed

+722
-410
lines changed

13 files changed

+722
-410
lines changed

src/compiletest/compiletest.rc

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ mod errors;
3333
use std::getopts;
3434
use std::test;
3535

36-
use core::result;
36+
use core::{result, either};
3737
use result::{Ok, Err};
3838

3939
use common::config;
@@ -158,7 +158,11 @@ pub fn test_opts(config: config) -> test::TestOpts {
158158
test::TestOpts {
159159
filter: config.filter,
160160
run_ignored: config.run_ignored,
161-
logfile: config.logfile.map(|s| s.to_str()),
161+
logfile: copy config.logfile,
162+
run_tests: true,
163+
run_benchmarks: false,
164+
save_results: option::None,
165+
compare_results: option::None
162166
}
163167
}
164168

@@ -210,13 +214,15 @@ pub fn make_test(config: config, testfile: &Path) -> test::TestDescAndFn {
210214
}
211215
}
212216

213-
pub fn make_test_name(config: config, testfile: &Path) -> ~str {
214-
fmt!("[%s] %s", mode_str(config.mode), testfile.to_str())
217+
pub fn make_test_name(config: config, testfile: &Path) -> test::TestName {
218+
test::DynTestName(fmt!("[%s] %s",
219+
mode_str(config.mode),
220+
testfile.to_str()))
215221
}
216222

217223
pub fn make_test_closure(config: config, testfile: &Path) -> test::TestFn {
218224
let testfile = testfile.to_str();
219-
fn~() { runtest::run(config, testfile) }
225+
test::DynTestFn(fn~() { runtest::run(config, testfile) })
220226
}
221227

222228
// Local Variables:

src/libcore/cmp.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,12 @@ pub pure fn gt<T: Ord>(v1: &T, v2: &T) -> bool {
8585
(*v1).gt(v2)
8686
}
8787

88+
#[inline(always)]
89+
pub pure fn min<T: Ord>(v1: T, v2: T) -> T {
90+
if v1 < v2 { v1 } else { v2 }
91+
}
92+
93+
#[inline(always)]
94+
pub pure fn max<T: Ord>(v1: T, v2: T) -> T {
95+
if v1 > v2 { v1 } else { v2 }
96+
}

src/libcore/either.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ pub pure fn unwrap_right<T,U>(eith: Either<T,U>) -> U {
145145
}
146146
}
147147

148-
impl<T, U> Either<T, U> {
148+
pub impl<T, U> Either<T, U> {
149149
#[inline(always)]
150150
fn either<V>(&self, f_left: fn(&T) -> V, f_right: fn(&U) -> V) -> V {
151151
either(f_left, f_right, self)

src/libcore/num/f64.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use to_str;
2121
use from_str;
2222

2323
pub use cmath::c_double_targ_consts::*;
24+
pub use cmp::{min, max};
2425

2526
macro_rules! delegate(
2627
(

src/libcore/num/int-template.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,14 @@ use vec;
2424
use i8;
2525
use i16;
2626
use i32;
27+
pub use cmp::{min, max};
2728

2829
pub const bits : uint = inst::bits;
2930
pub const bytes : uint = (inst::bits / 8);
3031

3132
pub const min_value: T = (-1 as T) << (bits - 1);
3233
pub const max_value: T = min_value - 1 as T;
3334

34-
#[inline(always)]
35-
pub pure fn min(x: T, y: T) -> T { if x < y { x } else { y } }
36-
#[inline(always)]
37-
pub pure fn max(x: T, y: T) -> T { if x > y { x } else { y } }
38-
3935
#[inline(always)]
4036
pub pure fn add(x: T, y: T) -> T { x + y }
4137
#[inline(always)]

src/libcore/num/num.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ pub trait One {
3939
static pure fn one() -> Self;
4040
}
4141

42+
pub pure fn abs<T: Ord Num Zero>(v: T) -> T {
43+
if v < Zero::zero() { v.neg() } else { v }
44+
}
45+
4246
pub trait Round {
4347
pure fn round(&self, mode: RoundMode) -> Self;
4448

src/libcore/num/uint-template.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,14 @@ use u8;
2727
use u16;
2828
use u32;
2929

30+
pub use cmp::{min, max};
31+
3032
pub const bits : uint = inst::bits;
3133
pub const bytes : uint = (inst::bits / 8);
3234

3335
pub const min_value: T = 0 as T;
3436
pub const max_value: T = 0 as T - 1 as T;
3537

36-
#[inline(always)]
37-
pub pure fn min(x: T, y: T) -> T { if x < y { x } else { y } }
38-
#[inline(always)]
39-
pub pure fn max(x: T, y: T) -> T { if x > y { x } else { y } }
40-
4138
#[inline(always)]
4239
pub pure fn add(x: T, y: T) -> T { x + y }
4340
#[inline(always)]

0 commit comments

Comments
 (0)