File tree Expand file tree Collapse file tree 2 files changed +45
-1
lines changed Expand file tree Collapse file tree 2 files changed +45
-1
lines changed Original file line number Diff line number Diff line change 1
1
---
2
- refs/heads/master: fc41ba167cac9f63eda4ee4c4927b7c905306d50
2
+ refs/heads/master: 084cfc10f5bea02f6bd32856eb2c343692af25c9
3
3
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4
4
refs/heads/snap-stage3: 60fba4d7d677ec098e6a43014132fe99f7547363
5
5
refs/heads/try: ebfe63cd1c0b5d23f7ea60c69b4fde2e30cfd42a
Original file line number Diff line number Diff line change @@ -1983,3 +1983,47 @@ mod bigint_tests {
1983
1983
assert_eq ! ( -Zero :: zero:: <BigInt >( ) , Zero :: zero:: <BigInt >( ) ) ;
1984
1984
}
1985
1985
}
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
+ }
You can’t perform that action at this time.
0 commit comments