caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Performance penalty of exception handling
@ 2015-09-16 19:08 Helmut Brandl
  2015-09-16 19:15 ` John Whitington
  2015-09-16 20:00 ` David Rajchenbach-Teller
  0 siblings, 2 replies; 5+ messages in thread
From: Helmut Brandl @ 2015-09-16 19:08 UTC (permalink / raw)
  To: caml-list

Hi all,

I use exeption handling quite frequently even in inner loops. A common 
pattern:

     let some_function ... =
             ...
            if cannot_compute then raise Not_found else value

     try
         let value = some_function ... in
         ...
     with Not_found ->
        handle_exception

I use this pattern even if the direct caller of "some_function" handles 
the exception. In many cases I could design "some_function" in a way 
that it returns an optional value and check the optional value in the 
caller. Is this significantly (at least 10%) faster? If not, I would 
stay with my present design. However I am pressed for performance in the 
inner loops (I am only interested in compilation to native).

Is there any information available on the preformance penalty of 
exception handling? Any hints? Thanks in advance.

Regards
Helmut

^ permalink raw reply	[flat|nested] 5+ messages in thread
* Re: [Caml-list] Performance penalty of exception handling
@ 2015-09-16 19:26 "Mark Adams"
  0 siblings, 0 replies; 5+ messages in thread
From: "Mark Adams" @ 2015-09-16 19:26 UTC (permalink / raw)
  To: helmut.brandl, caml-list

One problem is if your function that traps the exception is recursive - it
cannot be made tail recursive if the recursive call is within the 'try' ..
'with', which can cause stack overflow if it recurses thousands of times.

Mark Adams.

on 16/9/15 8:08 PM, Helmut Brandl <helmut.brandl@gmx.net> wrote:

> Hi all,
>
> I use exeption handling quite frequently even in inner loops. A common
> pattern:
>
> let some_function ... =
> ...
> if cannot_compute then raise Not_found else value
>
> try
> let value = some_function ... in
> ...
> with Not_found ->
> handle_exception
>
> I use this pattern even if the direct caller of "some_function" handles
> the exception. In many cases I could design "some_function" in a way
> that it returns an optional value and check the optional value in the
> caller. Is this significantly (at least 10%) faster? If not, I would
> stay with my present design. However I am pressed for performance in the
> inner loops (I am only interested in compilation to native).
>
> Is there any information available on the preformance penalty of
> exception handling? Any hints? Thanks in advance.
>
> Regards
> Helmut
>
> --
> Caml-list mailing list.  Subscription management and archives:
> https://sympa.inria.fr/sympa/arc/caml-list
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>
>
>

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

end of thread, other threads:[~2015-09-16 20:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-09-16 19:08 [Caml-list] Performance penalty of exception handling Helmut Brandl
2015-09-16 19:15 ` John Whitington
     [not found]   ` <CAKR7PS9iibAcWVMbjahdkVn6KBXUZa0U88KwZEkqc-LzfaBUKg@mail.gmail.com>
2015-09-16 19:51     ` Milan Stanojević
2015-09-16 20:00 ` David Rajchenbach-Teller
2015-09-16 19:26 "Mark Adams"

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).