On 22/02/2009, at 4:10 AM, Erick Tryzelaar wrote:
>
> I saw an interesting thread on [comp.lang.functional] (
> http://groups.google.com/group/comp.lang.functional/browse_frm/thread/99b8230c078d9b44)
>
> yesterday comparing the performance of a couple languages
> generating the mandelbrot fractal, and I thought it'd be interesting
> to see how felix compared. Turns out it does incredibly well. The
> times are in seconds when run on my laptop:
>
> | c++ | 1.92488 |
> | felix | 1.96676 |
> | ocamlopt | 5.81599 |
> | scala | 6.555 |
> | clojure | 12.7324 |
> | haskell | 96.2044 |
Felix should trash C++ .. :)
>
> mandelbrot.flx:
> {{{
> :::felix
> module sys::time_h
> {
> open C_hack;
>
> header "#include <sys/time.h>";
>
> type time_t = "time_t";
> type suseconds_t = "suseconds_t";
>
> fun _ctor_float: time_t -> float = "static_cast<float>($1)";
> fun _ctor_float: suseconds_t -> float = "static_cast<float>($1)";
>
> fun _ctor_double: time_t -> double = "static_cast<double>($1)";
> fun _ctor_double: suseconds_t -> double = "static_cast<double>($1)";
>
> cstruct timeval {
> tv_sec: time_t;
> tv_usec: suseconds_t;
> }
>
> proc gettimeofday: ptr[timeval] = "gettimeofday($1, NULL);";
>
> gen get_time () = {
> var tv:timeval;
> gettimeofday(addr tv);
> return _ctor_double(tv.tv_sec) + (_ctor_double(tv.tv_usec) /
> 1.0e6);
> }
> }
>
> val runs = 1;
> val max_iterations = 99888;
> fun iterate (ci:double, cr:double) = {
> val bailout = 4.0;
Check generated code to see if the usage of these is inlined.
Also check if the nested procedures slow things down.
No stack frames should be created: loop_ is tail rec.
> fun loop_ (zi:double, zr:double, i:int) =>
> if i <= max_iterations then
> let ?zr2 = zr * zr in
> let ?zi2 = zi * zi in
> if zi2 + zr2 <= bailout then
> loop_ (zr * zi * 2.0 + ci, zr2 - zi2 + cr, i + 1)
> else
> i
> endif
> else
> 0
> endif
> ;
> return loop_ (0.0, 0.0, 1);
> }
--
john skaller
[email protected]
------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
Felix-language mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/felix-language