Haskell compiler ghc - slow? 
Author Message
 Haskell compiler ghc - slow?

Hello,

I have just recently tried severel functional languages to find
one which suites my needs best. In this process I also compared the
speed of executables generated by different compilers of different
languages. Although some paper stated that the Haskell compiler "ghc"
belongs to the fastest, it apppeared to be surprisingly slow on a test
case I tried (nearly ten times slower than e.g. "clean" or "ocaml"). I
fear that I might have made a mistake in the implementation (I am not
(yet :)) an expert in this language.)
The test case I implemented was taken from a "clean"-example and
translated to Haskell. It is the "fast" version of Eratosthenes' sieve:

------------------------------------------------------------------------------
nr_of_primes = 10000
primes = 5 : sieve 7 4 primes

sieve::Int -> Int -> [Int] -> [Int]
sieve g i prs
   | is_prime prs g (truncate (sqrt (fromInt g))) =  g : sieve2 g i prs
   | True                                         = sieve (g + i) (6 - i) prs

sieve2::Int -> Int -> [Int] -> [Int]
sieve2 g i prs =  sieve (g + i) (6 - i) prs

is_prime::[Int] -> Int -> Int -> Bool  
is_prime (f:r) pr bd | f>bd         =  True
                     | mod pr f ==0 =  False
                     | True         =  is_prime r pr bd
select::[a] -> Int -> a
select (f:r) 1 =  f
select (f:r) n =  select r (n - 1)

main = print (select (2:3:primes) nr_of_primes)
------------------------------------------------------------------------------

The implementation of "clean" contains strictness annotations for the
formal arguments of the functions "Sieve" and "IsPrime". Is the lack of
it the source of inefficiency in the Haskell program? If yes, how can
I do the same in this language?  The "clean"-program looks as follows:

------------------------------------------------------------------------------
module fsieve
import StdClass;
import StdInt, StdReal

NrOfPrimes :== 10000

Primes::[Int]
Primes = pr where pr = [5 : Sieve 7 4 pr]

Sieve::Int !Int [Int] -> [Int]
Sieve g i prs
  | IsPrime prs g (toInt (sqrt (toReal g))) = [g : Sieve` g i prs]
                                            = Sieve (g + i) (6 - i) prs
Sieve`::Int Int [Int] -> [Int]
Sieve` g i prs =  Sieve (g + i) (6 - i) prs

IsPrime::[Int] !Int Int -> Bool
IsPrime [f:r] pr bd | f>bd        = True
                    | pr mod f==0 = False
                                  = IsPrime r pr bd
Select::[x] Int -> x
Select [f:r] 1 = f
Select [f:r] n = Select r (n - 1)

Start::Int
Start = Select [2, 3 : Primes] NrOfPrimes
------------------------------------------------------------------------------

I hope that some Haskell-guru can show me how this works...
I really like the syntax of Haskell and would be very disappointed if
it could not be done any better than that.

                          Best regards,
                             Markus

--
*  Markus Mottl              |  University of Economics and       *
*  Department of Applied     |  Business Administration           *
*  Computer Science          |  Vienna, Austria                   *



Sat, 20 Jan 2001 03:00:00 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Haskell / GHC: using field names

2. Haskell (GHC) - Help managing memory

3. Calling Haskell function from C (FFI) causes seg-fault (GHC,linux)

4. Haskell optimizations in GHC

5. GHC confusion, and a few haskell questions.

6. Concurrent Haskell (GHC) and Win32 Applications ?

7. Problem with GHC Haskell install and default libs

8. Hugs 1.4, Haskell: the Craft of Functional Programming, and GHC

9. ANNOUNCE: The Glasgow Haskell Compiler, version 5.04

10. which Haskell compiler/interpreter...?

11. seeking Haskell compiler supporting {-#line ...-}

12. ANNOUNCE: The Glasgow Haskell Compiler, version 4.02

 

 
Powered by phpBB® Forum Software