Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] Great Programming Language Shootout Revived
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2004-06-18 (17:07)
From: David Brown <caml-list@d...>
Subject: Re: [Caml-list] Great Programming Language Shootout Revived
On Fri, Jun 18, 2004 at 10:38:45AM -0500, Brian Hurt wrote:

> As a side note, there is a reason why C++ is slower than C, even if you're 
> compiling the exact same code.  C++ functions need to be able to handle 
> exceptions and unroll the stack, even if the function itself doesn't throw 
> or catch exceptions.  Even if unrolling the stack is a no-op, the function 
> generally needs to be able to both be handed off from another function's 
> stack unrolling, and hand off to another function's stack unrolling.

That depends on how exceptions are implemented.  There is a cost to
exceptions that can be paid at different times:

  - At each exception catch (try).
  - At each exception occurrence (raise).
  - At every call.

I've not actually seen the third case implemented.  For some test cases,
the actual function code generated by gcc and g++ are identical.  g++
contains an extra descriptor to facilitate stack unwinding.  It appears
that g++ pays most of the exception cost on raise (which is probably
best for C++ where exceptions are truly, exceptional).

So, aside from cache differences due to the layout of the structures,
the C-type code should execute at the same speed with C++ and C.

Most gnat (Ada) targets also implement these "zero cost" exceptions,
where the raise pays the cost, rather than catch.


To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: