Skip to content

Commit 951f1d0

Browse files
committed
Add .travis.yml. Bench closures return values. Feature gate.
1 parent abf82ff commit 951f1d0

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

.travis.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,10 @@ rust:
33
- nightly
44
- beta
55
- stable
6+
script: |
7+
cargo build --verbose &&
8+
cargo test --verbose &&
9+
([ $TRAVIS_RUST_VERSION != nightly ] || cargo test --verbose --features benchmarks) &&
10+
([ $TRAVIS_RUST_VERSION != nightly ] || cargo bench --verbose --features benchmarks bench)
611
notifications:
712
webhooks: http://build.servo.org:54856/travis

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@ documentation = "http://doc.servo.org/smallvec/"
1313
name = "smallvec"
1414
path = "lib.rs"
1515
doctest = false
16+
17+
[features]
18+
benchmarks = []

lib.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
//! Small vectors in various sizes. These store a certain number of elements inline and fall back
66
//! to the heap for larger allocations.
77
8-
#![feature(test)]
8+
#![cfg_attr(feature = "benchmarks", feature(test))]
99

1010
use std::borrow::{Borrow, BorrowMut};
1111
use std::cmp;
@@ -649,10 +649,8 @@ impl_array!(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 20, 24, 32,
649649

650650
#[cfg(test)]
651651
pub mod tests {
652-
extern crate test;
653652
use SmallVec;
654653
use std::borrow::ToOwned;
655-
use self::test::Bencher;
656654

657655
// We heap allocate all these strings so that double frees will show up under valgrind.
658656

@@ -1004,6 +1002,13 @@ pub mod tests {
10041002
assert_eq!(vec.clone().into_iter().len(), 3);
10051003
assert_eq!(vec.drain().len(), 3);
10061004
}
1005+
}
1006+
1007+
#[cfg(all(feature = "benchmarks", test))]
1008+
mod bench {
1009+
extern crate test;
1010+
use SmallVec;
1011+
use self::test::Bencher;
10071012

10081013
#[bench]
10091014
fn bench_push(b: &mut Bencher) {
@@ -1012,6 +1017,7 @@ pub mod tests {
10121017
for x in 0..100 {
10131018
vec.push(x);
10141019
}
1020+
vec
10151021
});
10161022
}
10171023

@@ -1022,6 +1028,7 @@ pub mod tests {
10221028
for x in 0..100 {
10231029
vec.insert(0, x);
10241030
}
1031+
vec
10251032
});
10261033
}
10271034

@@ -1030,6 +1037,7 @@ pub mod tests {
10301037
b.iter(|| {
10311038
let mut vec: SmallVec<[u64; 16]> = SmallVec::new();
10321039
vec.extend(0..100);
1040+
vec
10331041
});
10341042
}
10351043

@@ -1041,6 +1049,7 @@ pub mod tests {
10411049
vec.push(x);
10421050
vec.pop();
10431051
}
1052+
vec
10441053
});
10451054
}
10461055
}

0 commit comments

Comments
 (0)