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 mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id 86EA47F736 for ; Wed, 16 Sep 2015 21:51:38 +0200 (CEST) IronPort-PHdr: 9a23:L2J4SR9dXMqX6v9uRHKM819IXTAuvvDOBiVQ1KB80escTK2v8tzYMVDF4r011RmSDdmdsaMP0raL+4nbGkU+or+5+EgYd5JNUxJXwe43pCcHRPC/NEvgMfTxZDY7FskRHHVs/nW8LFQHUJ2mPw6anHS+4HYoFwnlMkItf6KuStKU1ZX8jrzvs7ToICx2xxOFKYtoKxu3qQiD/uI3uqBFbpgL9x3Sv3FTcP5Xz247bXianhL7+9vitMU7q3cYk7sb+sVBSaT3ebgjBfwdVWx+cjN92Mq+lx7DS0Ow5noAU2MZjh1OS1zH6xH8dpz2sibgu+xh1zOTJc33RqtyUjPk8qQ9DFfDgSIDfxo4632f3sd5iaYepBO6uzR+xZTVacebLqwtULnaeIY/RG5IWPFqSyVHBYGxcYoER74EPOJRqZLhj1QLpBq6QwKrAbW8mXdzmnbq0PhigKwaGgbc0VllRopWvQ== Authentication-Results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=milanst@gmail.com; spf=Pass smtp.mailfrom=milanst@gmail.com; spf=None smtp.helo=postmaster@mail-oi0-f41.google.com Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of milanst@gmail.com) identity=pra; client-ip=209.85.218.41; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="milanst@gmail.com"; x-sender="milanst@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of milanst@gmail.com designates 209.85.218.41 as permitted sender) identity=mailfrom; client-ip=209.85.218.41; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="milanst@gmail.com"; x-sender="milanst@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-oi0-f41.google.com) identity=helo; client-ip=209.85.218.41; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="milanst@gmail.com"; x-sender="postmaster@mail-oi0-f41.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0DhAQCvx/lVmynaVdFehGAGsUyTXwKBQQc8EAEBAQEBAQEBEAEBAQEBBgsLCSEugh2BfQoBAQMBEhEdARseAwwGBQMBBzcCAiIBEQEFARwGATSHdgEDCgineoEwPjGLRoFsgnmKKQoZJw1Wg34BAQEBAQUBAQEBAQEBFQEFDoZlhH2FFIJpgUMFlV6NBIFNlViCIBIjgRc4gi+CGSIziioBAQE X-IPAS-Result: A0DhAQCvx/lVmynaVdFehGAGsUyTXwKBQQc8EAEBAQEBAQEBEAEBAQEBBgsLCSEugh2BfQoBAQMBEhEdARseAwwGBQMBBzcCAiIBEQEFARwGATSHdgEDCgineoEwPjGLRoFsgnmKKQoZJw1Wg34BAQEBAQUBAQEBAQEBFQEFDoZlhH2FFIJpgUMFlV6NBIFNlViCIBIjgRc4gi+CGSIziioBAQE X-IronPort-AV: E=Sophos;i="5.17,541,1437429600"; d="scan'208";a="177935041" Received: from mail-oi0-f41.google.com ([209.85.218.41]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/AES128-GCM-SHA256; 16 Sep 2015 21:51:37 +0200 Received: by oiww128 with SMTP id w128so133387339oiw.2 for ; Wed, 16 Sep 2015 12:51:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=uMLMdxIYYr4cB56hK5+bB0XjXJcUH+19YXd1pTT+3So=; b=DfmHEs0SoEMg87sEofcKcVPyveDHj6YrZYsgC1dipmLgJQidg5D3TcVMEEcebjCfz0 8ZBVfIKaDMyCNgOPb76ChmHZRewnSMdbY8Hg5/bet0I8hfNdz27m6sGeHkSDDKjnRc6o fVTTTiXm49EHNwmJDcAqVE5I4UJhmLZZp1UxeSA1ODbiRxOCdBizbpfF4YecLRpwvZY9 ELeczfrHpIDsGRqRK1fy9dqAAOJi7TexcY/v3NObJSJDBgQmGzEgXb3x7Eu5MO+Mly6a t5mNY4JEJLaFwNSR+FMULyqjIzXrnCHYUddWFXDmhisa4uHkBOACY6eFfx4G1cB1Q6nH mvPQ== MIME-Version: 1.0 X-Received: by 10.202.86.208 with SMTP id k199mr24516969oib.102.1442433096336; Wed, 16 Sep 2015 12:51:36 -0700 (PDT) Received: by 10.202.175.198 with HTTP; Wed, 16 Sep 2015 12:51:36 -0700 (PDT) Received: by 10.202.175.198 with HTTP; Wed, 16 Sep 2015 12:51:36 -0700 (PDT) In-Reply-To: References: <55F9BE16.1020502@gmx.net> <55F9BFE3.2070904@coherentgraphics.co.uk> Date: Wed, 16 Sep 2015 15:51:36 -0400 Message-ID: From: =?UTF-8?Q?Milan_Stanojevi=C4=87?= To: John Whitington , Caml List Content-Type: multipart/alternative; boundary=001a113d809a51cc04051fe2a08a Subject: Re: [Caml-list] Performance penalty of exception handling --001a113d809a51cc04051fe2a08a Content-Type: text/plain; charset=UTF-8 (correctly sending to the list) > > 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. > > > The cost of an exception is not just its allocation. You also need to setup the exception handler. Also, backtrace recording is not cheap, so one should use raise_notrace primitive for cases like this. --001a113d809a51cc04051fe2a08a Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable

(correctly sending to the list)

> > Optional values often require allocation (and, the= refore, garbage collection). Unless your process is so short-lived that the= garbage collector never runs, exceptions are going to be faster. So, if yo= u 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 ca= uses an allocation.
> >
> > Constant exception constructors like Not_found, I believe, requir= e no allocation in recent versions of OCaml.
> >
>

The cost of an exception is not just its allocation. You als= o need to setup the exception handler. Also, backtrace recording is not che= ap, so one should use raise_notrace primitive for cases like this.

--001a113d809a51cc04051fe2a08a--