Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
speed: ghc vs gcc
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  Messages 1 - 25 of 126 - Collapse all  -  Translate all to Translated (View all originals)   Newer >
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Bulat Ziganshin  
View profile  
 More options Feb 20, 8:30 am
Newsgroups: fa.haskell
From: Bulat Ziganshin <bulat.zigans...@gmail.com>
Date: Fri, 20 Feb 2009 13:30:09 UTC
Local: Fri, Feb 20 2009 8:30 am
Subject: [Haskell-cafe] speed: ghc vs gcc
Hello haskell-cafe,

since there are no objective tests comparing ghc to gcc, i made my own
one. these are 3 programs, calculating sum in c++ and haskell:

main = print $ sum[1..10^9::Int]

main = print $ sum0 (10^9) 0

sum0 :: Int -> Int -> Int
sum0 0  !acc = acc
sum0 !x !acc = sum0 (x-1) (acc+x)

main()
{
  int sum=0;
  //for(int j=0; j<100;j++)
    for(int i=0; i<1000*1000*1000;i++)
      sum += i;
  return sum;

}

execution times:
 sum:
   ghc 6.6.1 -O2               : 12.433 secs
   ghc 6.10.1 -O2              : 12.792 secs
 sum-fast:
   ghc 6.6.1 -O2               :  1.919 secs
   ghc 6.10.1 -O2              :  1.856 secs
   ghc 6.10.1 -O2 -fvia-C      :  1.966 secs
 C++:
   gcc 3.4.5 -O3 -funroll-loops:  0.062 secs

--
Best regards,
 Bulat                          mailto:Bulat.Zigans...@gmail.com

_______________________________________________
Haskell-Cafe mailing list
Haskell-C...@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Miguel Mitrofanov  
View profile  
 More options Feb 20, 8:48 am
Newsgroups: fa.haskell
From: Miguel Mitrofanov <miguelim...@yandex.ru>
Date: Fri, 20 Feb 2009 13:48:45 UTC
Local: Fri, Feb 20 2009 8:48 am
Subject: Re: [Haskell-cafe] speed: ghc vs gcc
Ahem. Seems like you've included time spent on the runtime loading.

My results:

MigMit:~ MigMit$ gcc -o test -O3 -funroll-loops test.c && time ./test
-1243309312
real    0m0.066s
user    0m0.063s
sys     0m0.002s
MigMit:~ MigMit$ rm test; ghc -O2 --make test.hs && time ./test
Linking test ...
-243309312

real    0m3.201s
user    0m3.165s
sys     0m0.017s

While 3.201 vs. 0.066 seem to be a huge difference, 0.017 vs. 0.002 is  
not that bad.

On 20 Feb 2009, at 16:29, Bulat Ziganshin wrote:

_______________________________________________
Haskell-Cafe mailing list
Haskell-C...@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Miguel Mitrofanov  
View profile  
 More options Feb 20, 9:00 am
Newsgroups: fa.haskell
From: Miguel Mitrofanov <miguelim...@yandex.ru>
Date: Fri, 20 Feb 2009 14:00:32 UTC
Local: Fri, Feb 20 2009 9:00 am
Subject: Re: [Haskell-cafe] speed: ghc vs gcc
Forget it, my bad.

On 20 Feb 2009, at 16:48, Miguel Mitrofanov wrote:

_______________________________________________
Haskell-Cafe mailing list
Haskell-C...@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Bulat Ziganshin  
View profile  
 More options Feb 20, 9:05 am
Newsgroups: fa.haskell
From: Bulat Ziganshin <bulat.zigans...@gmail.com>
Date: Fri, 20 Feb 2009 14:05:43 UTC
Local: Fri, Feb 20 2009 9:05 am
Subject: Re[2]: [Haskell-cafe] speed: ghc vs gcc
Hello Miguel,

Friday, February 20, 2009, 4:48:15 PM, you wrote:

> Ahem. Seems like you've included time spent on the runtime loading.

for C, i've used additional 100x loop

> sys     0m0.002s
> sys     0m0.017s
> While 3.201 vs. 0.066 seem to be a huge difference, 0.017 vs. 0.002 is
> not that bad.

are you know that "sys" time means? :)

--
Best regards,
 Bulat                            mailto:Bulat.Zigans...@gmail.com

_______________________________________________
Haskell-Cafe mailing list
Haskell-C...@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Dan Doel  
View profile  
 More options Feb 20, 9:16 am
Newsgroups: fa.haskell
From: Dan Doel <dan.d...@gmail.com>
Date: Fri, 20 Feb 2009 14:16:15 UTC
Local: Fri, Feb 20 2009 9:16 am
Subject: Re: [Haskell-cafe] speed: ghc vs gcc
---- Test.hs ----

import Prelude hiding (sum, enumFromTo)

import Data.List.Stream (sum, unfoldr)

enumFromTo m n = unfoldr f m
 where f k | k <= n    = Just (k,k+1)
           | otherwise = Nothing

main = print . sum $ enumFromTo 1 (10^9 :: Int)

---- snip ----

dolio@zeke % time ./Test                                                            
500000000500000000
/Test  3.12s user 0.03s system 80% cpu 3.922 total
dolio@zeke % time ./Test-sum0                                                        
500000000500000000
/Test-sum0  3.47s user 0.02s system 80% cpu 4.348 total
dolio@zeke % time ./Test-sum0                                                        
500000000500000000
/Test-sum0  3.60s user 0.02s system 90% cpu 4.009 total
dolio@zeke % time ./Test                                                            
500000000500000000
/Test  3.11s user 0.02s system 81% cpu 3.846 total

---- snip ----

"Test-sum0" is with the sum0 function

"Test" is the code at the top of this mail.

-fvia-c -optc-O3 didn't seem to make a big difference with either Haskell
example, so they're both with the default backend.

Your C++ code runs slowly on my system (around 1 second), but that's because
it uses 32-bit ints, I guess (switching to long int sped it up).

-- Dan
_______________________________________________
Haskell-Cafe mailing list
Haskell-C...@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Dan Doel  
View profile  
 More options Feb 20, 9:39 am
Newsgroups: fa.haskell
From: Dan Doel <dan.d...@gmail.com>
Date: Fri, 20 Feb 2009 14:39:50 UTC
Local: Fri, Feb 20 2009 9:39 am
Subject: Re: [Haskell-cafe] speed: ghc vs gcc
Sorry for replying to myself, but I got suspicious about the 6ms runtime of
the 64-bit C++ code on my machine. So I looked at the assembly and found this:

    .LCFI1:                                                                                                            
            movabsq $499999999500000000, %rsi                                                                          
            movl    $_ZSt4cout, %edi                                                                                    
            pushq   %r12

I'm no assembly guru, but that makes me think that there's no actual
computation going on in the runtime for the 64-bit C++ program, whereas the
32-bit one is clearly doing work on my system, since it takes around 1 second.

Not that I'd be sad if GHC could reduce that whole constant at compile time,
but GCC isn't doing 1 billion adds in 6 (or even 60) milliseconds.
_______________________________________________
Haskell-Cafe mailing list
Haskell-C...@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Achim Schneider  
View profile  
 More options Feb 20, 9:45 am
Newsgroups: fa.haskell
From: Achim Schneider <bars...@web.de>
Date: Fri, 20 Feb 2009 14:45:26 UTC
Local: Fri, Feb 20 2009 9:45 am
Subject: [Haskell-cafe] Re: speed: ghc vs gcc

Bulat Ziganshin <bulat.zigans...@gmail.com> wrote:
> execution times:
>  sum:
>    ghc 6.6.1 -O2               : 12.433 secs
>    ghc 6.10.1 -O2              : 12.792 secs
>  sum-fast:
>    ghc 6.6.1 -O2               :  1.919 secs
>    ghc 6.10.1 -O2              :  1.856 secs
>    ghc 6.10.1 -O2 -fvia-C      :  1.966 secs
>  C++:
>    gcc 3.4.5 -O3 -funroll-loops:  0.062 secs

Nice! Now we know that gcc can calculate faster than Haskell can
calculate and print. Next time, use exitWith, please.

--
(c) this sig last receiving data processing entity. Inspect headers
for copyright history. All rights reserved. Copying, hiring, renting,
performance and/or quoting of this signature prohibited.

_______________________________________________
Haskell-Cafe mailing list
Haskell-C...@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
ChrisK  
View profile  
 More options Feb 20, 10:12 am
Newsgroups: fa.haskell
From: ChrisK <hask...@list.mightyreason.com>
Date: Fri, 20 Feb 2009 15:12:31 UTC
Local: Fri, Feb 20 2009 10:12 am
Subject: [Haskell-cafe] Re: speed: ghc vs gcc
On a G4:

s.hs (which does not need bang patterns) is:

> main = seq (sum0 (10^9) 0) (return ())

> sum0 :: Int -> Int -> Int
> sum0 0 acc = acc
> sum0 x acc = sum0 (x-1) $! (acc+x)

And s.c is (actually including 10^9, which Bulat's did not):

> main()
> {
>   int sum=0;
>   for(int i=1000*1000*1000; i>0; i--)
>       sum += i;
> }

I compiled them with

ghc --make -O2 s.hs -o shs
gcc -o sc -std=c99 -O3 -funroll-loops s.c

And timed them:

$ time ./shs

real    0m3.309s
user    0m3.008s
sys     0m0.026s

$ time ./sc

real    0m0.411s
user    0m0.316s
sys     0m0.006s

So C is 9.4 times faster.

And via-C did not help:

$ ghc -fvia-C -optc "-O3 -funroll-loops" --make -O2 s.hs -o shs-via-C
$ time ./shs-via-C

real    0m7.051s
user    0m3.010s
sys     0m0.050s

--
Chris

_______________________________________________
Haskell-Cafe mailing list
Haskell-C...@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Peter Verswyvelen  
View profile  
 More options Feb 20, 10:19 am
Newsgroups: fa.haskell
From: Peter Verswyvelen <bugf...@gmail.com>
Date: Fri, 20 Feb 2009 15:19:19 UTC
Local: Fri, Feb 20 2009 10:19 am
Subject: Re: [Haskell-cafe] Re: speed: ghc vs gcc

When I change the C++ program into:
int n;
scanf("%d", &n);

for(i=0; i<n;i++)
{
sum += i;

}

GCC need 100 milliseconds on my 3.0GHz new Xeon with loop unrolling
enabled.

Without loop unrolling GCC needs about 635ms

Visual C++ does it in 577 ms, generating the following code:

loop: add        rbx,rax
        inc         rax
       cmp       rax,rcx
       jl          loop

GHC with -O2 -fvia-c (the fastest I could make it) needs

13075 for the naive sum
2100 ms with sum0
2018 ms using the stream-fusion

Interesting to see that the stream-fusion was slower when not doing -fvia-c
(more than twice as slow with -O)

So GHC is about 3 to 4 times slower as Visual C++ / GCC without loop
unrolling, which is not too bad since GHC does not perform register
optimization and loop unrolling yet no?

_______________________________________________
Haskell-Cafe mailing list
Haskell-C...@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Bulat Ziganshin  
View profile  
 More options Feb 20, 10:23 am
Newsgroups: fa.haskell
From: Bulat Ziganshin <bulat.zigans...@gmail.com>
Date: Fri, 20 Feb 2009 15:23:06 UTC
Local: Fri, Feb 20 2009 10:23 am
Subject: Re: [Haskell-cafe] Re: speed: ghc vs gcc
Hello Achim,

Friday, February 20, 2009, 5:44:44 PM, you wrote:

> Nice! Now we know that gcc can calculate faster than Haskell can
> calculate and print. Next time, use exitWith, please.

it was done in order to simplify sources. are you really believe that
ghc needs more than 1 millisecond to print one number? :)

--
Best regards,
 Bulat                            mailto:Bulat.Zigans...@gmail.com

_______________________________________________
Haskell-Cafe mailing list
Haskell-C...@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Colin Paul Adams  
View profile  
 More options Feb 20, 10:23 am
Newsgroups: fa.haskell
From: Colin Paul Adams <co...@colina.demon.co.uk>
Date: Fri, 20 Feb 2009 15:23:22 UTC
Local: Fri, Feb 20 2009 10:23 am
Subject: Re: [Haskell-cafe] Re: speed: ghc vs gcc

>>>>> "Peter" == Peter Verswyvelen <bugf...@gmail.com> writes:

    Peter> So GHC is about 3 to 4 times slower as Visual C++ / GCC
    Peter> without loop unrolling, which is not too bad since GHC does
    Peter> not perform register optimization and loop unrolling yet
    Peter> no?

I would call it rather poor.

And I don't accept a since of that form as valid mitigation.
--
Colin Adams
Preston Lancashire
_______________________________________________
Haskell-Cafe mailing list
Haskell-C...@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Bulat Ziganshin  
View profile  
 More options Feb 20, 10:26 am
Newsgroups: fa.haskell
From: Bulat Ziganshin <bulat.zigans...@gmail.com>
Date: Fri, 20 Feb 2009 15:26:37 UTC
Local: Fri, Feb 20 2009 10:26 am
Subject: Re[2]: [Haskell-cafe] Re: speed: ghc vs gcc
Hello Peter,

Friday, February 20, 2009, 6:18:50 PM, you wrote:

> So GHC is about 3 to 4 times slower as Visual C++ / GCC without
> loop unrolling

why stop on disabling loop unrolling? there are lot of options we can
use if we want to make gcc slower :D

--
Best regards,
 Bulat                            mailto:Bulat.Zigans...@gmail.com

_______________________________________________
Haskell-Cafe mailing list
Haskell-C...@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Achim Schneider  
View profile  
 More options Feb 20, 10:30 am
Newsgroups: fa.haskell
From: Achim Schneider <bars...@web.de>
Date: Fri, 20 Feb 2009 15:30:28 UTC
Local: Fri, Feb 20 2009 10:30 am
Subject: [Haskell-cafe] Re: speed: ghc vs gcc

Bulat Ziganshin <bulat.zigans...@gmail.com> wrote:
> Hello Achim,

> Friday, February 20, 2009, 5:44:44 PM, you wrote:

> > Nice! Now we know that gcc can calculate faster than Haskell can
> > calculate and print. Next time, use exitWith, please.

> it was done in order to simplify sources. are you really believe that
> ghc needs more than 1 millisecond to print one number? :)

Well, I know that (Show a) is about as slow as you can get.

--
(c) this sig last receiving data processing entity. Inspect headers
for copyright history. All rights reserved. Copying, hiring, renting,
performance and/or quoting of this signature prohibited.

_______________________________________________
Haskell-Cafe mailing list
Haskell-C...@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Peter Verswyvelen  
View profile  
 More options Feb 20, 10:34 am
Newsgroups: fa.haskell
From: Peter Verswyvelen <bugf...@gmail.com>
Date: Fri, 20 Feb 2009 15:34:27 UTC
Local: Fri, Feb 20 2009 10:34 am
Subject: Re: [Haskell-cafe] Re: speed: ghc vs gcc

Well C# does it with a for loop in 2300ms, and when using a IEnumerable
sequence it needs 19936ms. Very much like the Haskell code. But of course
the Haskell code could optimize the sum I guess, I assume it is using the
lazy version of sum by default.

Anyway it was more of a question. Does GHC perform register allocation (e.g.
using graph colouring)  and loop unrolling?

On Fri, Feb 20, 2009 at 4:22 PM, Colin Paul Adams
<co...@colina.demon.co.uk>wrote:

_______________________________________________
Haskell-Cafe mailing list
Haskell-C...@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Bulat Ziganshin  
View profile  
 More options Feb 20, 10:45 am
Newsgroups: fa.haskell
From: Bulat Ziganshin <bulat.zigans...@gmail.com>
Date: Fri, 20 Feb 2009 15:45:15 UTC
Local: Fri, Feb 20 2009 10:45 am
Subject: Re[2]: [Haskell-cafe] Re: speed: ghc vs gcc
Hello Peter,

Friday, February 20, 2009, 6:34:04 PM, you wrote:

> Well C# does it with a for loop in 2300ms, and when using a
> IEnumerable sequence it needs 19936ms. Very much like the Haskell
> code. But of course the Haskell code could optimize the sum I guess,
> I assume it is using the lazy version of sum by default.

the question is what is the natural for every language

> Anyway it was more of a question. Does GHC perform register
> allocation (e.g. using graph colouring)  and loop unrolling?

afaik, ghc can be compared with 20-years old C compilers. it uses
registers for performing tight loops but has very simple register
allocation procedure. also it doesn't unroll loops

--
Best regards,
 Bulat                            mailto:Bulat.Zigans...@gmail.com

_______________________________________________
Haskell-Cafe mailing list
Haskell-C...@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
David Leimbach  
View profile  
 More options Feb 20, 10:52 am
Newsgroups: fa.haskell
From: David Leimbach <leim...@gmail.com>
Date: Fri, 20 Feb 2009 15:52:40 UTC
Local: Fri, Feb 20 2009 10:52 am
Subject: Re: [Haskell-cafe] speed: ghc vs gcc

The GCC optimizer must know that you can't return a value to user space of
that large as a return result.

In Haskell you're printing it... why not print it in C++?

_______________________________________________
Haskell-Cafe mailing list
Haskell-C...@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Achim Schneider  
View profile  
 More options Feb 20, 10:57 am
Newsgroups: fa.haskell
From: Achim Schneider <bars...@web.de>
Date: Fri, 20 Feb 2009 15:57:21 UTC
Local: Fri, Feb 20 2009 10:57 am
Subject: [Haskell-cafe] Re: speed: ghc vs gcc

hmmm... do we have magic-hash vector types and folds and maps on them?
I'm only asking because gcc fails to use _anything_ but plain registers.

--
(c) this sig last receiving data processing entity. Inspect headers
for copyright history. All rights reserved. Copying, hiring, renting,
performance and/or quoting of this signature prohibited.

_______________________________________________
Haskell-Cafe mailing list
Haskell-C...@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Dan Doel  
View profile  
 More options Feb 20, 11:01 am
Newsgroups: fa.haskell
From: Dan Doel <dan.d...@gmail.com>
Date: Fri, 20 Feb 2009 16:01:23 UTC
Local: Fri, Feb 20 2009 11:01 am
Subject: Re: [Haskell-cafe] speed: ghc vs gcc
On Friday 20 February 2009 10:52:03 am David Leimbach wrote:

> The GCC optimizer must know that you can't return a value to user space of
> that large as a return result.

> In Haskell you're printing it... why not print it in C++?

I actually changed my local copy to print out the result (since I wanted to
make sure it was using 64 bit ints). It didn't make a difference in the timing
(of either the 32 or 64 bit version).
_______________________________________________
Haskell-Cafe mailing list
Haskell-C...@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Bulat Ziganshin  
View profile  
 More options Feb 20, 11:18 am
Newsgroups: fa.haskell
From: Bulat Ziganshin <bulat.zigans...@gmail.com>
Date: Fri, 20 Feb 2009 16:18:11 UTC
Local: Fri, Feb 20 2009 11:18 am
Subject: Re[2]: [Haskell-cafe] speed: ghc vs gcc
Hello David,

Friday, February 20, 2009, 6:52:03 PM, you wrote:

> In Haskell you're printing it... why not print it in C++?

in order to omit #include <stdio> line

--
Best regards,
 Bulat                            mailto:Bulat.Zigans...@gmail.com

_______________________________________________
Haskell-Cafe mailing list
Haskell-C...@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Felipe Lessa  
View profile  
 More options Feb 20, 11:31 am
Newsgroups: fa.haskell
From: Felipe Lessa <felipe.le...@gmail.com>
Date: Fri, 20 Feb 2009 16:31:59 UTC
Local: Fri, Feb 20 2009 11:31 am
Subject: Re: Re[2]: [Haskell-cafe] speed: ghc vs gcc
Hey guys, what about the LLVM bindings? They seem nice for tight loops this one.

--
Felipe.
_______________________________________________
Haskell-Cafe mailing list
Haskell-C...@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Don Stewart  
View profile  
 More options Feb 20, 11:42 am
Newsgroups: fa.haskell
From: Don Stewart <d...@galois.com>
Date: Fri, 20 Feb 2009 16:42:54 UTC
Local: Fri, Feb 20 2009 11:42 am
Subject: Re: [Haskell-cafe] speed: ghc vs gcc
bulat.ziganshin:

> Hello haskell-cafe,

> since there are no objective tests comparing ghc to gcc, i made my own
> one. these are 3 programs, calculating sum in c++ and haskell:

Wonderful. Thank you!

> main = print $ sum[1..10^9::Int]

This won't be comparable to your loop below, as 'sum' is a left fold
(which doesn't fuse under build/foldr).

You should use the list implementation from the stream-fusion package (or
uvector) if you're expecting it to fuse to the following loop:

> main = print $ sum0 (10^9) 0

> sum0 :: Int -> Int -> Int
> sum0 0  !acc = acc
> sum0 !x !acc = sum0 (x-1) (acc+x)

Note the bang patterns aren't required here. It compiles to the
following core:

    $wsum0 :: Int# -> Int# -> Int#
    $wsum0 =
      \ (ww_sON :: Int#) (ww1_sOR :: Int#) ->
          case ww_sON of ds_XD0 {
                _ -> $wsum0 (-# ds_XD0 1) (+# ww1_sOR ds_XD0);
                0 -> ww1_sOR

which is perfect.

    Main_zdwsum0_info:
      testq       %rsi, %rsi
      movq        %rsi, %rax
      jne .L2
      movq        %rdi, %rbx
      jmp *(%rbp)
    .L2:
      leaq        -1(%rsi), %rsi
      addq        %rax, %rdi
      jmp Main_zdwsum0_info

Which seems ... OK.

    $ ghc-core A.hs -fvia-C -optc-O3
    $ time ./A
    500000000500000000
    ./A  1.12s user 0.00s system 99% cpu 1.127 total

Works for me. That's on linux x86_64, gcc 4.4

Trying -fasm:

    Main_zdwsum0_info:
    .LcQs:
      movq %rsi,%rax
      testq %rax,%rax
      jne .LcQw
      movq %rdi,%rbx
      jmp *(%rbp)
    .LcQw:
      movq %rdi,%rcx
      addq %rax,%rcx
      leaq -1(%rax),%rsi
      movq %rcx,%rdi
      jmp Main_zdwsum0_info

    $ time ./A
    500000000500000000
    ./A  1.65s user 0.00s system 98% cpu 1.677 total

Is  a bit slower.

> main()
> {
>   int sum=0;
>   //for(int j=0; j<100;j++)
>     for(int i=0; i<1000*1000*1000;i++)
>       sum += i;
>   return sum;
> }

Well, that's a bit different. It doesn't print the result, and it returns a different
results on 64 bit....

    $ gcc -O0 t.c
    $ time ./a.out
    -1243309312
    ./a.out  3.99s user 0.00s system 88% cpu 4.500 total

    $ gcc -O1 t.c
    $ time ./a.out
    -1243309312
    ./a.out  0.88s user 0.00s system 99% cpu 0.892 total

    $ gcc -O3 -funroll-loops t.c
    $ time ./a.out
    -1243309312
    ./a.out  0.31s user 0.00s system 97% cpu 0.318 total

I don't get anything near the 0.062s which is interesting.
The print statement slows things down, I guess...

So we have:

    ghc -fvia-C -O2             1.127
    ghc -fasm                   1.677
    gcc -O0                     4.500
    gcc -O3 -funroll-loops      0.318

So. some lessons. GHC is around 3-4x slower on this tight loop. (Which isn't as
bad as it used to be).

That's actually a worse margin than any current shootout program, where we are no
worse than 2.9 slower on larger things:

    http://shootout.alioth.debian.org/u64q/benchmark.php?test=all&lang=gh...

> execution times:
>  sum:
>    ghc 6.6.1 -O2               : 12.433 secs
>    ghc 6.10.1 -O2              : 12.792 secs
>  sum-fast:
>    ghc 6.6.1 -O2               :  1.919 secs
>    ghc 6.10.1 -O2              :  1.856 secs
>    ghc 6.10.1 -O2 -fvia-C      :  1.966 secs
>  C++:
>    gcc 3.4.5 -O3 -funroll-loops:  0.062 secs

I couldn't reproduce your final number.

Now, given GHC gets most of the way there -- I think this might make a good bug
report against GHC head, so we can see if the new register allocator helps any.

    http://hackage.haskell.org/trac/ghc/newticket?type=bug

Thanks for the report, Bulat!

-- Don
_______________________________________________
Haskell-Cafe mailing list
Haskell-C...@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Bulat Ziganshin  
View profile  
 More options Feb 20, 12:17 pm
Newsgroups: fa.haskell
From: Bulat Ziganshin <bulat.zigans...@gmail.com>
Date: Fri, 20 Feb 2009 17:17:57 UTC
Local: Fri, Feb 20 2009 12:17 pm
Subject: Re[2]: [Haskell-cafe] speed: ghc vs gcc
Hello Don,

Friday, February 20, 2009, 7:41:33 PM, you wrote:

>> main = print $ sum[1..10^9::Int]
> This won't be comparable to your loop below, as 'sum' is a left fold
> (which doesn't fuse under build/foldr).
> You should use the list implementation from the stream-fusion package (or
> uvector) if you're expecting it to fuse to the following loop:

it was comparison of native haskell, low-level haskell (which is
harder to write than native C) and native C. stream-fusion and any
other packages provides libraries for some tasks but they can't make faster
maps, for example. so i used plain list

> Which seems ... OK.

really? :D

> Well, that's a bit different. It doesn't print the result, and it returns a different
> results on 64 bit....

doesn't matter for testing speed

> I don't get anything near the 0.062s which is interesting.

it was beautiful gcc optimization - it added 8 values at once. with
xor results are:

xor.hs      12.605
xor-fast.hs  1.856
xor.cpp      0.339

> The print statement slows things down, I guess...

are you really believe that printing one number needs so much time? :)

> So we have:
>     ghc -fvia-C -O2             1.127
>     ghc -fasm                   1.677
>     gcc -O0                     4.500
>     gcc -O3 -funroll-loops      0.318

why not compare to ghc -O0? also you can disable loop unrolling in gcc
and unroll loops manually in haskell. or you can generate asm code on
the fly. there are plenty of tricks to "prove" that gcc generates bad
code :D

> So. some lessons. GHC is around 3-4x slower on this tight loop. (Which isn't as
> bad as it used to be).

really? what i see: low-level haskell code is usually 3 times harder
to write and 3 times slower than gcc code. native haskell code is tens
to thousands times slower than C code (just recall that real programs
use type classes and monads in addition to laziness)

> That's actually a worse margin than any current shootout program, where we are no
> worse than 2.9 slower on larger things:

1) most benchmarks there depend on libraries speed. in one test, for
example, php is winner
2) for the sum program ghc libs was modified to win in benchmark
3) the remaining 1 or 2 programs that measure speed of ghc-generated
code was hardly optimized using low-level code, so they don't have
anything common with real haskell code most of us write every day

> Now, given GHC gets most of the way there -- I think this might make a good bug
> report against GHC head, so we can see if the new register allocator helps any.

you mean that 6.11 includes new allocator? in that case you can
test it too

i believe that ghc developers are able to test sum performance without my
bugreports :D

--
Best regards,
 Bulat                            mailto:Bulat.Zigans...@gmail.com

_______________________________________________
Haskell-Cafe mailing list
Haskell-C...@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Thomas Davie  
View profile  
 More options Feb 20, 1:02 pm
Newsgroups: fa.haskell
From: Thomas Davie <tom.da...@gmail.com>
Date: Fri, 20 Feb 2009 18:02:54 UTC
Local: Fri, Feb 20 2009 1:02 pm
Subject: Re: Re[4]: [Haskell-cafe] speed: ghc vs gcc

On 20 Feb 2009, at 18:37, Bulat Ziganshin wrote:

> Hello Thomas,

> Friday, February 20, 2009, 8:22:33 PM, you wrote:

>>> doesn't matter for testing speed

>> okay then, I wrote a faster Haskell version:

>> main = print "Hello world"

> for you, any language will be fast enough :D

No C was very slow, I've been waiting for this implementation to  
terminate for over an hour now:

int main (int argc, char ** argv)
{
     while (1) { }
     printf ("1234567890");

}

_______________________________________________
Haskell-Cafe mailing list
Haskell-C...@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Don Stewart  
View profile  
 More options Feb 20, 1:40 pm
Newsgroups: fa.haskell
From: Don Stewart <d...@galois.com>
Date: Fri, 20 Feb 2009 18:40:54 UTC
Local: Fri, Feb 20 2009 1:40 pm
Subject: Re: [Haskell-cafe] speed: ghc vs gcc
bulat.ziganshin:

> Friday, February 20, 2009, 7:41:33 PM, you wrote:

> >> main = print $ sum[1..10^9::Int]

> > This won't be comparable to your loop below, as 'sum' is a left fold
> > (which doesn't fuse under build/foldr).

> > You should use the list implementation from the stream-fusion package (or
> > uvector) if you're expecting it to fuse to the following loop:

> it was comparison of native haskell, low-level haskell (which is
> harder to write than native C) and native C. stream-fusion and any
> other packages provides libraries for some tasks but they can't make faster
> maps, for example. so i used plain list

Hmm? Maybe you're not familiar with the state of the art?

    $ cabal install uvector

Write a loop at a high level:

    import Data.Array.Vector

    main = print (sumU (enumFromToU 1 (10^9 :: Int)))

Compile it:

    $ ghc-core A.hs -O2 -fvia-C -optc-O3

Yielding:

    s16h_info:
      cmpq        6(%rbx), %rdi
      jg  .L2
      addq        %rdi, %rsi
      leaq        1(%rdi), %rdi
      jmp s16h_info

Running:

    $ time ./A
    500000000500000000
    ./A  0.97s user 0.01s system 99% cpu 0.982 total

Now, (trying to avoid the baiting...) this is actually *very*
interesting. Why is this faster than the manual recursion we did earlier
why do we get better assembly?  Again, if you stick to specifics, there's some
interesting things we can learn here.

> > Which seems ... OK.

> really? :D

No, see above.

> > I don't get anything near the 0.062s which is interesting.

> it was beautiful gcc optimization - it added 8 values at once. with
> xor results are:

> xor.hs      12.605
> xor-fast.hs  1.856
> xor.cpp      0.339

GCC is a good loop optimiser. But apparently not my GCC.

> > So we have:

> >     ghc -fvia-C -O2             1.127
> >     ghc -fasm                   1.677
> >     gcc -O0                     4.500
> >     gcc -O3 -funroll-loops      0.318

> why not compare to ghc -O0? also you can disable loop unrolling in gcc
> and unroll loops manually in haskell. or you can generate asm code on
> the fly. there are plenty of tricks to "prove" that gcc generates bad
> code :D

No, we want to show (I imagine) that GHC is within a factor or two of "C".
I usually set my benchmark to beat gcc -O0 fwiw, and then to hope to be within
2x of optimised C. I'm not sure what you're standards are.

> > So. some lessons. GHC is around 3-4x slower on this tight loop. (Which isn't as
> > bad as it used to be).

> really? what i see: low-level haskell code is usually 3 times harder
> to write and 3 times slower than gcc code. native haskell code is tens
> to thousands times slower than C code (just recall that real programs
> use type classes and monads in addition to laziness)

"thousands times", now you're just undermining your own credibility
here. Stick to what you can measure. If anything we'd expect GCC's magic loop
skillz to be less useful on large code bases.

> > That's actually a worse margin than any current shootout program, where we are no
> > worse than 2.9 slower on larger things:

> 1) most benchmarks there depend on libraries speed. in one test, for
> example, php is winner
> 2) for the sum program ghc libs was modified to win in benchmark

It is interesting that the < 2.9x slower in the shootout is pretty much what
we found in this benchmark too.

> 3) the remaining 1 or 2 programs that measure speed of ghc-generated
> code was hardly optimized using low-level code, so they don't have
> anything common with real haskell code most of us write every day

Depends on where you work.

> > Now, given GHC gets most of the way there -- I think this might make a good bug
> > report against GHC head, so we can see if the new register allocator helps any.

> you mean that 6.11 includes new allocator? in that case you can
> test it too

Yes.

    http://hackage.haskell.org/trac/ghc/wiki/Commentary/Compiler/Integrat...

> i believe that ghc developers are able to test sum performance without my
> bugreports :D

No! This is not how open source works! You *should submit bug reports* and *analysis*.
It is so so much more useful than complaining and throwing stones.

-- Don
_______________________________________________
Haskell-Cafe mailing list
Haskell-C...@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Achim Schneider  
View profile  
 More options Feb 20, 2:13 pm
Newsgroups: fa.haskell
From: Achim Schneider <bars...@web.de>
Date: Fri, 20 Feb 2009 19:13:40 UTC
Local: Fri, Feb 20 2009 2:13 pm
Subject: [Haskell-cafe] Re: speed: ghc vs gcc

Don Stewart <d...@galois.com> wrote:
> No! This is not how open source works! You *should submit bug
> reports* and *analysis*. It is so so much more useful than
> complaining and throwing stones.

Exactly. I don't know where, but I read that the vast majorities of
Linux bugs are reported, nailed, and then fixed, by at least three
different persons: The first reports a misbehaviour, the second manages
to find it surfacing in a certain line of code, the third instantly
knows how to make it go away.

--
(c) this sig last receiving data processing entity. Inspect headers
for copyright history. All rights reserved. Copying, hiring, renting,
performance and/or quoting of this signature prohibited.

_______________________________________________
Haskell-Cafe mailing list
Haskell-C...@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Messages 1 - 25 of 126   Newer >
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google