Enable testing on stable Rust

This commit is contained in:
Alex Crichton 2015-05-19 09:22:06 -07:00
parent edcb6295ff
commit a6a399d52e
7 changed files with 81 additions and 74 deletions

View File

@ -1,15 +1,26 @@
language: rust
rust:
- 1.0.0
- beta
- nightly
sudo: false
script:
- cargo build --verbose
- cargo test --verbose
- |
[ $TRAVIS_RUST_VERSION != nightly ] || (
cargo bench &&
cargo test --verbose --manifest-path=num-macros/Cargo.toml
)
- cargo doc
after_success: |
[ $TRAVIS_BRANCH = master ] &&
[ $TRAVIS_PULL_REQUEST = false ] &&
[ $TRAVIS_RUST_VERSION = nightly ] &&
echo '<meta http-equiv=refresh content=0;url=num/index.html>' > target/doc/index.html &&
sudo pip install ghp-import &&
ghp-import -n target/doc &&
git push -fq https://${TOKEN}@github.com/${TRAVIS_REPO_SLUG}.git gh-pages
pip install ghp-import --user $USER &&
$HOME/.local/bin/ghp-import -n target/doc &&
git push -qf https://${TOKEN}@github.com/${TRAVIS_REPO_SLUG}.git gh-pages
env:
global:
secure: NNQ8QgQFZ05OhljZiuCg39AEPU7Yhko/shFlJG1lqYFoFrELibSmBPd7zJsTubufHRddn0ed6IH7qPLnzWJ/cS+dxwAopuqCFzGMOcd/JW8DJgD5PUBA8EVh8x0tNFJVxxdnGac1ufRneWMvMIxH2hO1DMc+8FZBBd7u1DNG1Lk=

View File

@ -16,6 +16,3 @@ rational, and complex types.
[dependencies]
rustc-serialize = "0.3.13"
rand = "0.3.8"
[dev-dependencies]
num-macros = { path = "num-macros", version = "0.1.22" }

64
benches/bigint.rs Normal file
View File

@ -0,0 +1,64 @@
#![feature(test)]
extern crate test;
extern crate num;
use std::mem::replace;
use test::Bencher;
use num::{BigUint, Zero, One, FromPrimitive};
fn factorial(n: usize) -> BigUint {
let mut f: BigUint = One::one();
for i in 1..(n+1) {
let bu: BigUint = FromPrimitive::from_usize(i).unwrap();
f = f * bu;
}
f
}
fn fib(n: usize) -> BigUint {
let mut f0: BigUint = Zero::zero();
let mut f1: BigUint = One::one();
for _ in 0..n {
let f2 = f0 + &f1;
f0 = replace(&mut f1, f2);
}
f0
}
#[bench]
fn factorial_100(b: &mut Bencher) {
b.iter(|| {
factorial(100);
});
}
#[bench]
fn fib_100(b: &mut Bencher) {
b.iter(|| {
fib(100);
});
}
#[bench]
fn to_string(b: &mut Bencher) {
let fac = factorial(100);
let fib = fib(100);
b.iter(|| {
fac.to_string();
});
b.iter(|| {
fib.to_string();
});
}
#[bench]
fn shr(b: &mut Bencher) {
let n = { let one : BigUint = One::one(); one << 1000 };
b.iter(|| {
let mut m = n.clone();
for _ in 0..10 {
m = m >> 1;
}
})
}

View File

@ -14,3 +14,6 @@ Numeric syntax extensions.
[lib]
name = "num_macros"
plugin = true
[dev-dependencies]
num = { path = "..", version = "*" }

View File

@ -3450,69 +3450,3 @@ mod bigint_tests {
let _n: BigInt = rng.gen_bigint_range(&u, &l);
}
}
#[cfg(test)]
mod bench {
extern crate test;
use self::test::Bencher;
use super::BigUint;
use std::mem::replace;
use {Zero, One, FromPrimitive};
fn factorial(n: usize) -> BigUint {
let mut f: BigUint = One::one();
for i in 1..(n+1) {
let bu: BigUint = FromPrimitive::from_usize(i).unwrap();
f = f * bu;
}
f
}
fn fib(n: usize) -> BigUint {
let mut f0: BigUint = Zero::zero();
let mut f1: BigUint = One::one();
for _ in 0..n {
let f2 = f0 + &f1;
f0 = replace(&mut f1, f2);
}
f0
}
#[bench]
fn factorial_100(b: &mut Bencher) {
b.iter(|| {
factorial(100);
});
}
#[bench]
fn fib_100(b: &mut Bencher) {
b.iter(|| {
fib(100);
});
}
#[bench]
fn to_string(b: &mut Bencher) {
let fac = factorial(100);
let fib = fib(100);
b.iter(|| {
fac.to_string();
});
b.iter(|| {
fib.to_string();
});
}
#[bench]
fn shr(b: &mut Bencher) {
let n = { let one : BigUint = One::one(); one << 1000 };
b.iter(|| {
let mut m = n.clone();
for _ in 0..10 {
m = m >> 1;
}
})
}
}

View File

@ -42,8 +42,6 @@
//! ```
//!
//! [newt]: https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method
//#![cfg_attr(test, deny(warnings))]
#![cfg_attr(test, feature(test))]
#![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
html_root_url = "http://doc.rust-lang.org/num/",