From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by sympa.inria.fr (Postfix) with ESMTPS id E5CB07F736 for ; Wed, 16 Sep 2015 21:15:53 +0200 (CEST) IronPort-PHdr: 9a23:vh0M7R1gADUaiv8ZsmDT+DRfVm0co7zxezQtwd8ZsegfKvad9pjvdHbS+e9qxAeQG96Lt7Qe2qGP6PCocFdDyKjCmUhKSIZLWR4BhJdetC0bK+nBN3fGKuX3ZTcxBsVIWQwt1Xi6NU9IBJS2PAWK8TWM5DIfUi/yKRBybrysXNWC04LthqvroM2bSj4LrQT+SIs6FA+xowTVu5teqqpZAYF19CH0pGBVcf9d32JiKAHbtR/94sCt4MwrqHwI6LoJvvRNWqTifqk+UacQTHF/azh0t4XXskzjQA+K+2dUeH8flBZMS1zF4RX/Q4u3uDHzsOZ58CafLYvwQKxiChq46KI+ahjojm84Nz8l8WfYlst2xPZZpxKnjxd4w4PObYeJO+B3ZqPcdshcTm0HQ8UHBH8JOZ+1c4ZaV7lJBu1ftYSo4gJW9RY= Authentication-Results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=john@coherentgraphics.co.uk; spf=None smtp.mailfrom=john@coherentgraphics.co.uk; spf=None smtp.helo=postmaster@mx2.ukhost4u.com Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of john@coherentgraphics.co.uk) identity=pra; client-ip=188.64.186.7; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="john@coherentgraphics.co.uk"; x-sender="john@coherentgraphics.co.uk"; x-conformance=sidf_compatible Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of john@coherentgraphics.co.uk) identity=mailfrom; client-ip=188.64.186.7; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="john@coherentgraphics.co.uk"; x-sender="john@coherentgraphics.co.uk"; x-conformance=sidf_compatible Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@mx2.ukhost4u.com) identity=helo; client-ip=188.64.186.7; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="john@coherentgraphics.co.uk"; x-sender="postmaster@mx2.ukhost4u.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0CiAQCOv/lVlAe6QLxeg3dvvy+FfQKBSDwQAQEBAQEBAQEQAQEBAQcNCQkSDy6CHYIHAQEEIwQRQAEQCwcRAgIFFgsCAgkDAgECAUUGDog3AbVKlDwBAQEBBgEBAQEBHYEiik6EWjMHgmmBQwEElV6NVXyHM44lg2w4hC2KFYEFAQEB X-IPAS-Result: A0CiAQCOv/lVlAe6QLxeg3dvvy+FfQKBSDwQAQEBAQEBAQEQAQEBAQcNCQkSDy6CHYIHAQEEIwQRQAEQCwcRAgIFFgsCAgkDAgECAUUGDog3AbVKlDwBAQEBBgEBAQEBHYEiik6EWjMHgmmBQwEElV6NVXyHM44lg2w4hC2KFYEFAQEB X-IronPort-AV: E=Sophos;i="5.17,541,1437429600"; d="scan'208";a="147514976" Received: from mx2.ukhost4u.com ([188.64.186.7]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Sep 2015 21:15:53 +0200 Received: from bluechip4.ukhost4u.com ([188.64.184.40]) by mx2.ukhost4u.com with esmtps (TLSv1.2:DHE-RSA-AES256-SHA:256) (Exim 4.85) (envelope-from ) id 1ZcIBJ-0002pJ-7l; Wed, 16 Sep 2015 20:15:52 +0100 Received: from [86.6.29.62] (port=55153 helo=[192.168.0.3]) by bluechip4.ukhost4u.com with esmtpsa (TLSv1:DHE-RSA-CAMELLIA256-SHA:256) (Exim 4.85) (envelope-from ) id 1ZcIBJ-002DXH-8e; Wed, 16 Sep 2015 20:15:49 +0100 Message-ID: <55F9BFE3.2070904@coherentgraphics.co.uk> Date: Wed, 16 Sep 2015 20:15:47 +0100 From: John Whitington User-Agent: Postbox 4.0.4 (Macintosh/20150825) MIME-Version: 1.0 To: Helmut Brandl CC: caml-list@inria.fr References: <55F9BE16.1020502@gmx.net> In-Reply-To: <55F9BE16.1020502@gmx.net> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-OutGoing-Spam-Status: No, score=-2.9 X-AuthUser: john@coherentgraphics.co.uk X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - bluechip4.ukhost4u.com X-AntiAbuse: Original Domain - X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - coherentgraphics.co.uk X-Get-Message-Sender-Via: bluechip4.ukhost4u.com: none X-Filter-ID: s0sct1PQhAABKnZB5plbIf846yA3iTMvdsVmSdrHPMU9CTo+a6AtXGOZ5s/KMzk3GXNQvgP2LFpq 9ASq+UttQVdnVZRbSbCw02atTs6NF1R7dm22g8ZTXxeN7Ad3M3NivjPaqpweUyctkTSmNp2C+ghf 9feTWzRD9S85mcBTGjaRG7M2xi6Ys3RI5acdNJISItz9evqtkdrZNEjxzWSzTJ7qOFOdAGlN4xEZ QCfEDFxc9aUV1oY4fX3W5eOCNA393sJsCUcpETsSZ4j+8kUQfxJnBLHVTpcRbTwSnuyX+YKeoyGa fcbKzH9GC8YKTr+2mkSFsCO6K3i+7z8cp0GscMOpyKA69LF1Ge2GaGfxmfo1ZXGc3/ntEZK3Ojlp gChctitGj+xB8QTD+FPu2z0DqhEVniihuDwEGDcmr6e3OPSpFbWmMpZ5nXAzjsr6aeLvqbdKeSdl 73iErNZBpGDxnl0OVUxGiYX6prK4XsdM2WVVd5KEVyyiZtyV1NyfVYC+lFyaiSgCQQ1OadeU0o3K JIww9s6Jb4w6woF5MenkiP9SlSttYuxWDZ9FX4ihA3cbk3DD1jNa4o/p6he37ljlgw5yOQQAOnDs zL3QP8BSjeH74O4hBSz/kkmPgL+fgIguoEYjPzScCbRmfgCiiUz2B6+uTfIGiTnWm7OT0KTVp0Ug EAXxHPsrbcvf9TFhj09CQnD6foiOFcFJ99/wCEtKCA== X-Report-Abuse-To: spam@mx1.ukhost4u.com X-Filter-Fingerprint: IFrWXGses7OKB5S5G8/dJRn/7L7+nnclbWGk7OJ1jHJA3cTUQ1R++keuE7RDJ8Kg3RbMLUalw1oC mj99/u+PoqoVy8a3lsStJtAvpObFX0Wok1JBYnOLzfRIhlEHQynLUpndEJ0YoaLytXXo8BMTaVt0 ARHRi6XGuAluI1udprFy32DUYpEhA3j9NJFmItfypuoazoDH3m92PL21GfhFYWcYmGLKZUTyGy/B A6iJtsD8WFC+rpTT4JYvoDjVeZUw3fI9smEy0EupqfCN6sn6Zg== X-Originating-IP: 188.64.184.40 X-SpamExperts-Domain: bluechip4.ukhost4u.com X-SpamExperts-Username: 188.64.184.40 X-SpamExperts-Outgoing-Class: ham X-SpamExperts-Outgoing-Evidence: Combined (0.00) X-Recommended-Action: accept Subject: Re: [Caml-list] Performance penalty of exception handling Hi, Helmut Brandl wrote: > 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? Optional values often require allocation (and, therefore, garbage collection). Unless your process is so short-lived that the garbage collector never runs, exceptions are going to be faster. So, if you benchmark this, make sure your benchmarks run for a while. Someone who knows the compiler better than I will be able to tell you if (Some x) when immediately pattern-matched across a function call causes an allocation. Constant exception constructors like Not_found, I believe, require no allocation in recent versions of OCaml. Cheers, -- John Whitington Director, Coherent Graphics Ltd http://www.coherentpdf.com/