Skip to content

Commit 63c7a09

Browse files
committed
---
yaml --- r: 78794 b: refs/heads/try c: 084cfc1 h: refs/heads/master v: v3
1 parent e92c4d4 commit 63c7a09

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: 25ed29a0edb3d48fef843a0b818ee68faf2252da
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 60fba4d7d677ec098e6a43014132fe99f7547363
5-
refs/heads/try: fc41ba167cac9f63eda4ee4c4927b7c905306d50
5+
refs/heads/try: 084cfc10f5bea02f6bd32856eb2c343692af25c9
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c

branches/try/src/libextra/num/bigint.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1983,3 +1983,47 @@ mod bigint_tests {
19831983
assert_eq!(-Zero::zero::<BigInt>(), Zero::zero::<BigInt>());
19841984
}
19851985
}
1986+
1987+
#[cfg(test)]
1988+
mod bench {
1989+
use super::*;
1990+
use std::{iterator, util};
1991+
use std::num::{Zero, One};
1992+
use extra::test::BenchHarness;
1993+
1994+
fn factorial(n: uint) -> BigUint {
1995+
let mut f = One::one::<BigUint>();
1996+
for i in iterator::range_inclusive(1, n) {
1997+
f = f * BigUint::from_uint(i);
1998+
}
1999+
f
2000+
}
2001+
2002+
fn fib(n: uint) -> BigUint {
2003+
let mut f0 = Zero::zero::<BigUint>();
2004+
let mut f1 = One::one::<BigUint>();
2005+
for _ in range(0, n) {
2006+
let f2 = f0 + f1;
2007+
f0 = util::replace(&mut f1, f2);
2008+
}
2009+
f0
2010+
}
2011+
2012+
#[bench]
2013+
fn factorial_100(bh: &mut BenchHarness) {
2014+
do bh.iter { factorial(100); }
2015+
}
2016+
2017+
#[bench]
2018+
fn fib_500(bh: &mut BenchHarness) {
2019+
do bh.iter { fib(100); }
2020+
}
2021+
2022+
#[bench]
2023+
fn to_str(bh: &mut BenchHarness) {
2024+
let fac = factorial(100);
2025+
let fib = fib(100);
2026+
do bh.iter { fac.to_str(); }
2027+
do bh.iter { fib.to_str(); }
2028+
}
2029+
}

0 commit comments

Comments
 (0)