diff options
| author | bors <bors@rust-lang.org> | 2014-10-14 04:02:48 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-10-14 04:02:48 +0000 |
| commit | a1e2eb0395941f5ca79cd59c8ab0a9f3133a2df0 (patch) | |
| tree | 2782a6efa84382e234077244930b2d78d54ce7ee /src/libstd/num | |
| parent | 1c3ddd297128a96f72be09bddf138e4e603a7aa1 (diff) | |
| parent | 2e2d681d88d99c4bb7033b852f98d6f979af5672 (diff) | |
| download | rust-a1e2eb0395941f5ca79cd59c8ab0a9f3133a2df0.tar.gz rust-a1e2eb0395941f5ca79cd59c8ab0a9f3133a2df0.zip | |
auto merge of #18017 : alexcrichton/rust/rollup, r=alexcrichton
Diffstat (limited to 'src/libstd/num')
| -rw-r--r-- | src/libstd/num/strconv.rs | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/src/libstd/num/strconv.rs b/src/libstd/num/strconv.rs index f97bbe0dc8e..48ee7664c16 100644 --- a/src/libstd/num/strconv.rs +++ b/src/libstd/num/strconv.rs @@ -819,72 +819,82 @@ mod bench { mod uint { use super::test::Bencher; use rand::{weak_rng, Rng}; - use num::ToStrRadix; + use std::fmt; + + #[inline] + fn to_string(x: uint, base: u8) { + format!("{}", fmt::radix(x, base)); + } #[bench] fn to_str_bin(b: &mut Bencher) { let mut rng = weak_rng(); - b.iter(|| { rng.gen::<uint>().to_str_radix(2); }) + b.iter(|| { to_string(rng.gen::<uint>(), 2); }) } #[bench] fn to_str_oct(b: &mut Bencher) { let mut rng = weak_rng(); - b.iter(|| { rng.gen::<uint>().to_str_radix(8); }) + b.iter(|| { to_string(rng.gen::<uint>(), 8); }) } #[bench] fn to_str_dec(b: &mut Bencher) { let mut rng = weak_rng(); - b.iter(|| { rng.gen::<uint>().to_str_radix(10); }) + b.iter(|| { to_string(rng.gen::<uint>(), 10); }) } #[bench] fn to_str_hex(b: &mut Bencher) { let mut rng = weak_rng(); - b.iter(|| { rng.gen::<uint>().to_str_radix(16); }) + b.iter(|| { to_string(rng.gen::<uint>(), 16); }) } #[bench] fn to_str_base_36(b: &mut Bencher) { let mut rng = weak_rng(); - b.iter(|| { rng.gen::<uint>().to_str_radix(36); }) + b.iter(|| { to_string(rng.gen::<uint>(), 36); }) } } mod int { use super::test::Bencher; use rand::{weak_rng, Rng}; - use num::ToStrRadix; + use std::fmt; + + #[inline] + fn to_string(x: int, base: u8) { + format!("{}", fmt::radix(x, base)); + } #[bench] fn to_str_bin(b: &mut Bencher) { let mut rng = weak_rng(); - b.iter(|| { rng.gen::<int>().to_str_radix(2); }) + b.iter(|| { to_string(rng.gen::<int>(), 2); }) } #[bench] fn to_str_oct(b: &mut Bencher) { let mut rng = weak_rng(); - b.iter(|| { rng.gen::<int>().to_str_radix(8); }) + b.iter(|| { to_string(rng.gen::<int>(), 8); }) } #[bench] fn to_str_dec(b: &mut Bencher) { let mut rng = weak_rng(); - b.iter(|| { rng.gen::<int>().to_str_radix(10); }) + b.iter(|| { to_string(rng.gen::<int>(), 10); }) } #[bench] fn to_str_hex(b: &mut Bencher) { let mut rng = weak_rng(); - b.iter(|| { rng.gen::<int>().to_str_radix(16); }) + b.iter(|| { to_string(rng.gen::<int>(), 16); }) } #[bench] fn to_str_base_36(b: &mut Bencher) { let mut rng = weak_rng(); - b.iter(|| { rng.gen::<int>().to_str_radix(36); }) + b.iter(|| { to_string(rng.gen::<int>(), 36); }) } } |
