caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* ackermann test
@ 2005-02-09  3:57 skaller
  2005-02-09  4:09 ` [Caml-list] " Michael Walter
  0 siblings, 1 reply; 9+ messages in thread
From: skaller @ 2005-02-09  3:57 UTC (permalink / raw)
  To: caml-list

Entirely for amusement, current timings for 
ackermanns function, ack(3,y):

     Felix Ocaml bytecode  Felix/opt     C -O3  Ocaml native code
---------------------------------------------------------
y=10 113        12             7          1.8          0.4
y=11  ?         50            55         16            2
y=12  ?        220           290        113            9

Times in seconds on 700MHz PIII. 

For y=12, my disk light went on occasionally 
(i.e the process was hitting VM), looks like the size of 
stack frames begins to dominate as y increases?

Be interesting to see comparison with ocaml bytecode/JIT.

-- 
John Skaller, mailto:skaller@users.sf.net
voice: 061-2-9660-0850, 
snail: PO BOX 401 Glebe NSW 2037 Australia
Checkout the Felix programming language http://felix.sf.net




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Caml-list] ackermann test
  2005-02-09  3:57 ackermann test skaller
@ 2005-02-09  4:09 ` Michael Walter
  2005-02-09  4:13   ` skaller
  0 siblings, 1 reply; 9+ messages in thread
From: Michael Walter @ 2005-02-09  4:09 UTC (permalink / raw)
  To: skaller; +Cc: caml-list

Where can I find the C code you are using?

Michael


On Tue, 08 Feb 2005 20:02:28 -0800 (PST), skaller
<skaller@users.sourceforge.net> wrote:
> Entirely for amusement, current timings for
> ackermanns function, ack(3,y):
> 
>      Felix Ocaml bytecode  Felix/opt     C -O3  Ocaml native code
> ---------------------------------------------------------
> y=10 113        12             7          1.8          0.4
> y=11  ?         50            55         16            2
> y=12  ?        220           290        113            9
> 
> Times in seconds on 700MHz PIII.
> 
> For y=12, my disk light went on occasionally
> (i.e the process was hitting VM), looks like the size of
> stack frames begins to dominate as y increases?
> 
> Be interesting to see comparison with ocaml bytecode/JIT.
> 
> --
> John Skaller, mailto:skaller@users.sf.net
> voice: 061-2-9660-0850,
> snail: PO BOX 401 Glebe NSW 2037 Australia
> Checkout the Felix programming language http://felix.sf.net
> 
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Caml-list] ackermann test
  2005-02-09  4:09 ` [Caml-list] " Michael Walter
@ 2005-02-09  4:13   ` skaller
  2005-02-09  9:26     ` Marcin 'Qrczak' Kowalczyk
  0 siblings, 1 reply; 9+ messages in thread
From: skaller @ 2005-02-09  4:13 UTC (permalink / raw)
  To: Michael Walter; +Cc: caml-list

On Wed, 2005-02-09 at 15:09, Michael Walter wrote:
> Where can I find the C code you are using?

int ack(int x, int y) {
  return x==0? y+1: (y==0? ack(x-1,1):ack(x-1,ack(x,y-1)));
}

-- 
John Skaller, mailto:skaller@users.sf.net
voice: 061-2-9660-0850, 
snail: PO BOX 401 Glebe NSW 2037 Australia
Checkout the Felix programming language http://felix.sf.net




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Caml-list] ackermann test
  2005-02-09  4:13   ` skaller
@ 2005-02-09  9:26     ` Marcin 'Qrczak' Kowalczyk
  2005-02-09 11:17       ` Oliver Bandel
  0 siblings, 1 reply; 9+ messages in thread
From: Marcin 'Qrczak' Kowalczyk @ 2005-02-09  9:26 UTC (permalink / raw)
  To: caml-list

skaller <skaller@users.sourceforge.net> writes:

>> Where can I find the C code you are using?
>
> int ack(int x, int y) {
>   return x==0? y+1: (y==0? ack(x-1,1):ack(x-1,ack(x,y-1)));
> }

If you write it like this:

int ack(int x, int y) {
   if (x==0) return y+1;
   if (y==0) return ack(x-1,1);
   return ack(x-1,ack(x,y-1));
}

then gcc-3.4.3 generates better code (optimizes tail calls).
-fomit-frame-pointer further speeds it up.

-- 
   __("<         Marcin Kowalczyk
   \__/       qrczak@knm.org.pl
    ^^     http://qrnik.knm.org.pl/~qrczak/


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Caml-list] ackermann test
  2005-02-09  9:26     ` Marcin 'Qrczak' Kowalczyk
@ 2005-02-09 11:17       ` Oliver Bandel
  2005-02-09 13:34         ` skaller
  0 siblings, 1 reply; 9+ messages in thread
From: Oliver Bandel @ 2005-02-09 11:17 UTC (permalink / raw)
  To: caml-list

On Wed, Feb 09, 2005 at 10:26:39AM +0100, Marcin 'Qrczak' Kowalczyk wrote:
> skaller <skaller@users.sourceforge.net> writes:
> 
> >> Where can I find the C code you are using?
> >
> > int ack(int x, int y) {
> >   return x==0? y+1: (y==0? ack(x-1,1):ack(x-1,ack(x,y-1)));
> > }
> 
> If you write it like this:
> 
> int ack(int x, int y) {
>    if (x==0) return y+1;
>    if (y==0) return ack(x-1,1);
>    return ack(x-1,ack(x,y-1));
> }
> 
> then gcc-3.4.3 generates better code (optimizes tail calls).
> -fomit-frame-pointer further speeds it up.


Would be nice to have the comlete benchmark again - now with this
code (or with an added row for this C-Code).

So we can compare, what reults will yielded by that different code
on the same platform for which we saw the other benchmark values.

Ciao,
   Oliver


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Caml-list] ackermann test
  2005-02-09 11:17       ` Oliver Bandel
@ 2005-02-09 13:34         ` skaller
  2005-02-09 14:00           ` Marcin 'Qrczak' Kowalczyk
  0 siblings, 1 reply; 9+ messages in thread
From: skaller @ 2005-02-09 13:34 UTC (permalink / raw)
  To: Oliver Bandel; +Cc: caml-list

On Wed, 2005-02-09 at 22:17, Oliver Bandel wrote:

> > int ack(int x, int y) {
> >    if (x==0) return y+1;
> >    if (y==0) return ack(x-1,1);
> >    return ack(x-1,ack(x,y-1));
> > }
> > 
> > then gcc-3.4.3 generates better code (optimizes tail calls).
> > -fomit-frame-pointer further speeds it up.

> 
> Would be nice to have the comlete benchmark again - now with this
> code (or with an added row for this C-Code).

I only have gcc 3.2.2.  With -fomit-frame-pointer and -O3 and -static
for the new C:

       new C  w/o old C  new Felix  old Felix  HACKED  Ocamlopt Ocamlb
y=10    0.5   0.8    1.8       2.9          7     10      0.4     12 
y=11    7.4   12.5  16        28           55     75      2       50
y=12   64     98   113       180          290    370      9      220

w/o -- new C code without -fomit-frame-pointer

'old Felix' + 2 ints on stack frame
'HACKED'    + 4 ints on stack frame

Felix puts at least 2 extra words on the stack,
probably 3, plus possibly g++ is saving the 
'this' pointer which is a 4 word overhead
compared to the C code.

-- 
John Skaller, mailto:skaller@users.sf.net
voice: 061-2-9660-0850, 
snail: PO BOX 401 Glebe NSW 2037 Australia
Checkout the Felix programming language http://felix.sf.net




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Caml-list] ackermann test
  2005-02-09 13:34         ` skaller
@ 2005-02-09 14:00           ` Marcin 'Qrczak' Kowalczyk
  2005-02-09 15:55             ` skaller
  0 siblings, 1 reply; 9+ messages in thread
From: Marcin 'Qrczak' Kowalczyk @ 2005-02-09 14:00 UTC (permalink / raw)
  To: caml-list

skaller <skaller@users.sourceforge.net> writes:

> I only have gcc 3.2.2.  With -fomit-frame-pointer and -O3 and -static
> for the new C:
>
>        new C  w/o old C  new Felix  old Felix  HACKED  Ocamlopt Ocamlb
> y=10    0.5   0.8    1.8       2.9          7     10      0.4     12 
> y=11    7.4   12.5  16        28           55     75      2       50
> y=12   64     98   113       180          290    370      9      220

A further speedup in C:

__attribute__((regparm(2)))
int ack(int x, int y) {
   ...
}

BTW, gcc -O2 and -O3 give the same code here.

gcc generates some redundant register moves (I guess regparm is not
optimized as well as it could because it's not common), so ocamlopt
is still marginally faster.

-- 
   __("<         Marcin Kowalczyk
   \__/       qrczak@knm.org.pl
    ^^     http://qrnik.knm.org.pl/~qrczak/


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Caml-list] ackermann test
  2005-02-09 14:00           ` Marcin 'Qrczak' Kowalczyk
@ 2005-02-09 15:55             ` skaller
  2005-02-09 16:51               ` Jon Harrop
  0 siblings, 1 reply; 9+ messages in thread
From: skaller @ 2005-02-09 15:55 UTC (permalink / raw)
  To: Marcin 'Qrczak' Kowalczyk; +Cc: caml-list

On Thu, 2005-02-10 at 01:00, Marcin 'Qrczak' Kowalczyk wrote:
> skaller <skaller@users.sourceforge.net> writes:

> >        new C  w/o old C  new Felix  old Felix  HACKED  Ocamlopt Ocamlb
> > y=10    0.5   0.8    1.8       2.9          7     10      0.4     12 
> > y=11    7.4   12.5  16        28           55     75      2       50
> > y=12   64     98   113       180          290    370      9      220
> 
> A further speedup in C:
> 
> __attribute__((regparm(2)))
> int ack(int x, int y) {
>    ...
> }

You are certainly not kidding! With that change:

         C         Felix   Ocamlopt
Y=10   0.5         0.8        0.4
Y=11   2.1         9.3        2
Y=12  21.5        87          9


-- 
John Skaller, mailto:skaller@users.sf.net
voice: 061-2-9660-0850, 
snail: PO BOX 401 Glebe NSW 2037 Australia
Checkout the Felix programming language http://felix.sf.net




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Caml-list] ackermann test
  2005-02-09 15:55             ` skaller
@ 2005-02-09 16:51               ` Jon Harrop
  0 siblings, 0 replies; 9+ messages in thread
From: Jon Harrop @ 2005-02-09 16:51 UTC (permalink / raw)
  To: caml-list

On Tuesday 08 February 2005 10:43, Xavier Leroy wrote:
> Ah, another micro-benchmark.  Great pasttime!

No way, that nbody benchmark was _huge_! ;-)

-- 
Dr Jon D Harrop, Flying Frog Consultancy Ltd.


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2005-02-09 16:49 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-02-09  3:57 ackermann test skaller
2005-02-09  4:09 ` [Caml-list] " Michael Walter
2005-02-09  4:13   ` skaller
2005-02-09  9:26     ` Marcin 'Qrczak' Kowalczyk
2005-02-09 11:17       ` Oliver Bandel
2005-02-09 13:34         ` skaller
2005-02-09 14:00           ` Marcin 'Qrczak' Kowalczyk
2005-02-09 15:55             ` skaller
2005-02-09 16:51               ` Jon Harrop

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).