[GHC] #6000: Performance of Fibonnaci compare to Python

GHC cvs-ghc at haskell.org
Thu Apr 12 13:02:27 CEST 2012


#6000: Performance of Fibonnaci compare to Python
------------------------------------+---------------------------------------
    Reporter:  guest                |       Owner:                         
        Type:  bug                  |      Status:  new                    
    Priority:  normal               |   Milestone:                         
   Component:  Compiler             |     Version:  7.4.1                  
    Keywords:  python, performance  |          Os:  Linux                  
Architecture:  x86_64 (amd64)       |     Failure:  Runtime performance bug
  Difficulty:  Unknown              |    Testcase:                         
   Blockedby:                       |    Blocking:                         
     Related:                       |  
------------------------------------+---------------------------------------
Changes (by simonmar):

  * difficulty:  => Unknown


Old description:

> There's a 4 second, unjustified, difference in performance between the
> following Python fibonacci implementation and it's equivalent Haskell
> implementation (though the output core seems to be just fine!).
>
> -----PYTHON------
> def fib(n):
>     one = 0
>     two = 1
>     for i in range(0,n):
>         temp = two
>         two = one + two
>         one = temp
>     return one
>
> if __name__ == "__main__":
>     print fib(1000000);
>
> ----HASKELL-------
> {-# LANGUAGE BangPatterns #-}
>
> fib :: Int -> Integer
> fib 0 = 0
> fib 1 = 1
> fib n = fib' 0 1 2 where
>     fib' _ y n' | n' > n = y
>     fib' !x !y !n' = fib' y (x+y) (n'+1)
>
> main = fib 1000000 `seq` return ()

New description:

 There's a 4 second, unjustified, difference in performance between the
 following Python fibonacci implementation and it's equivalent Haskell
 implementation (though the output core seems to be just fine!).
 {{{
 -----PYTHON------
 def fib(n):
     one = 0
     two = 1
     for i in range(0,n):
         temp = two
         two = one + two
         one = temp
     return one

 if __name__ == "__main__":
     print fib(1000000);
 }}}
 {{{
 ----HASKELL-------
 {-# LANGUAGE BangPatterns #-}

 fib :: Int -> Integer
 fib 0 = 0
 fib 1 = 1
 fib n = fib' 0 1 2 where
     fib' _ y n' | n' > n = y
     fib' !x !y !n' = fib' y (x+y) (n'+1)

 main = fib 1000000 `seq` return ()
 }}}

--

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/6000#comment:4>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler



More information about the Glasgow-haskell-bugs mailing list