<DIV> </DIV>
<DIV>I think gcc 4.x have much better optimizations than 3.x since SSA added.</DIV>
<DIV>I donot know if there are very good IR for functional language optimization.</DIV>
<DIV> </DIV>
<DIV>Is it hard for STG language to analysis this kind of code?</DIV>
<DIV>> go !x !y !i<BR>> | i == 1000000000 = printf "%f\n" (x+y)<BR>> | otherwise = go (x*y/3) (x*9) (i+1)<BR></DIV>
<DIV>btw: I always hope to see a C/C++ language compiler writen by haskell.</DIV>
<DIV>I think it might be much easier to add a new optimization :)</DIV>
<DIV ></DIV><BR>在2007-02-11,Rafael Almeida <almeidaraf@gmail.com> 写道:<BR>
<BLOCKQUOTE style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid"><PRE>On 2/10/07, Donald Bruce Stewart <dons@cse.unsw.edu.au> wrote:
> The following C program was described on #haskell
>
> #include <stdio.h>
>
> int main()
> {
> double x = 1.0/3.0;
> double y = 3.0;
> int i = 1;
> for (; i<=1000000000; i++) {
> x = x*y/3.0;
> y = x*9.0;
> }
> printf("%f\n", x+y);
> }
>
>
> Which was translated to the following Haskell:
>
> {-# OPTIONS -fexcess-precision #-}
>
> import Text.Printf
>
> main = go (1/3) 3 1
>
> go :: Double -> Double -> Int -> IO ()
> go !x !y !i
> | i == 1000000000 = printf "%f\n" (x+y)
> | otherwise = go (x*y/3) (x*9) (i+1)
I've compiled the exactly same programs, passing the same parameters to
the compiler as you did, but I've got a very different result:
$ ghc -O -fexcess-precision -fbang-patterns -optc-O3 -optc-ffast-math\
-optc-mfpmath=sse -optc-msse2 loop.hs -o haskell_loop
$ time ./haskell_loop
3.3333333333333335
real 0m14.092s
user 0m14.057s
sys 0m0.036s
$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 6.6
While the haskell program took so long, the C program went really faster
than the haskell version:
$ gcc -O3 -ffast-math -mfpmath=sse -msse2 -std=c99 loop.c -o c_loop
$ time ./c_loop
3.333333
real 0m0.001s
user 0m0.000s
sys 0m0.000s
$ gcc --version
gcc (GCC) 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)
I'm using debian etch (linux), my processor is a pentium 4 3.0ghz, which
has sse and sse2 (or at least /proc/cpuinfo says so). As for memory, it
probably doesn't matter much in this test, but I have 512mB of ram.
In a similar thread that was posted at comp.lang.functional (it was
actually regarding ocaml vs C++, you can find it on google groups at
http://tinyurl.com/292ps6 ) the same kind of discrepancy occurred.
Showing that this kind of benchmarking is usually not very accurate or,
at least, that my processor is not well suited for functional languages
:P.
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
</PRE></BLOCKQUOTE><br><!-- footer --><br>
<hr>
<span style="font-size:12px;line-height:15px; color:#000">新年短信特多,回来回去回不完!怎么办</span> <a style="font-size:12px;line-height:15px; color:blue; text-decoration:underline;font-family:Tahoma" href="http://allyesbjafa.allyes.com/main/adfclick?db=allyesbjafa&bid=1728,863,31&cid=825,171,1&sid=1731&show=ignore&url=http://www.fetion.com.cn/">用飞信群发短信!</a>