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 7EF0A7F75C for ; Wed, 10 Sep 2014 14:26:38 +0200 (CEST) Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of info@gerd-stolpmann.de) identity=pra; client-ip=212.227.17.10; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="info@gerd-stolpmann.de"; x-sender="info@gerd-stolpmann.de"; x-conformance=sidf_compatible Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of info@gerd-stolpmann.de) identity=mailfrom; client-ip=212.227.17.10; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="info@gerd-stolpmann.de"; x-sender="info@gerd-stolpmann.de"; x-conformance=sidf_compatible Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@mout.kundenserver.de) identity=helo; client-ip=212.227.17.10; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="info@gerd-stolpmann.de"; x-sender="postmaster@mout.kundenserver.de"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AuIBACdDEFTU4xEKm2dsb2JhbABZg2BXyikKh0wBgQ4WEAEBAQEBBgsLCRQqhAMBAQQBVSQFCwsYLlcGEwmIMQwJqiyTNAEXiWSFQyYHgjgPRIFBBYYai2CDd4R1iUkFj1YcgV5qAYJOAQEB X-IPAS-Result: AuIBACdDEFTU4xEKm2dsb2JhbABZg2BXyikKh0wBgQ4WEAEBAQEBBgsLCRQqhAMBAQQBVSQFCwsYLlcGEwmIMQwJqiyTNAEXiWSFQyYHgjgPRIFBBYYai2CDd4R1iUkFj1YcgV5qAYJOAQEB X-IronPort-AV: E=Sophos;i="5.04,498,1406584800"; d="asc'?scan'208";a="78439116" Received: from mout.kundenserver.de ([212.227.17.10]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 10 Sep 2014 14:26:34 +0200 Received: from office1.lan.sumadev.de (dslb-088-068-067-138.088.068.pools.vodafone-ip.de [88.68.67.138]) by mrelayeu.kundenserver.de (node=mreue104) with ESMTP (Nemesis) id 0M2u1e-1YKD4p32Bi-00sfaK; Wed, 10 Sep 2014 14:26:33 +0200 Received: from [192.168.5.106] (dslb-088-068-067-138.088.068.pools.vodafone-ip.de [88.68.67.138]) by office1.lan.sumadev.de (Postfix) with ESMTPSA id 223B1DC270; Wed, 10 Sep 2014 14:26:33 +0200 (CEST) Message-ID: <1410351988.3003.19.camel@thinkpad> From: Gerd Stolpmann To: Yotam Barnoy Cc: SF Markus Elfring , Ocaml Mailing List Date: Wed, 10 Sep 2014 14:26:28 +0200 In-Reply-To: References: <54101221.3010304@users.sourceforge.net> <1410348425.3003.11.camel@thinkpad> Content-Type: multipart/signed; micalg="pgp-sha1"; protocol="application/pgp-signature"; boundary="=-567b+DNNih4ZKpC/PNqO" X-Mailer: Evolution 3.10.4-0ubuntu2 Mime-Version: 1.0 X-Provags-ID: V02:K0:nfx//mv2ZKb3u61BK9uqOSiwdPhv/hwlH5n24J1rTpz asvPhL4VsLSeWDySw2Met0L4Kxb9coxkHfHmaWGHhWXfF5zLK6 eXsc3y3S+GE1GTHD1KqMX+/bUHpqk1pESmdGQzhAkRqEw/mpaI H6mMbwHn5FApZhHXzftFrptRXxKBptttsMoACqAsWMeVziMSdq al8as+O3jXJQZRJBAeUsIMtWSaE/bgrPdUWny7liuXOBRLkHw+ OfYel/V1ZAu2TrQOMhZMZSGDzEP9IOMkSaiKdXW0c+D8qRftLd UCpXD93Zmumoef1vVh8dRxEDwh4qRkGiZeKfEsGFgR3bfM3V4M YLRYBmx9C1svFSC1CFli9INiiZ3QuurWAxHlI7gm5 X-UI-Out-Filterresults: notjunk:1; Subject: Re: [Caml-list] Clarification for the configuration of comparison functions --=-567b+DNNih4ZKpC/PNqO Content-Type: text/plain; charset="ISO-8859-15" Content-Transfer-Encoding: quoted-printable Am Mittwoch, den 10.09.2014, 08:07 -0400 schrieb Yotam Barnoy: > Another reason is performance. The generic, polymorphic comparison > function drops you out into C (which has a cost) Don't think so. compare doesn't allocate memory, so the few extra instructions in caml_c_call for making allocation available from C aren't required. Calling compare shouldn't be slower than calling a function written in OCaml. > and has to compare every single possible value combination. That's more of a problem: there is a dispatch on the type of value to compare, and this costs a bit of time. There is something else that can speed up a custom compare: you can also store a hash of the value inside the value, and use that for speeding up comparison, e.g. type t =3D ... type t_cmp =3D t * int let wrap x =3D (x, Hashtbl.hash x) let my_compare (x1,h1) (x2,h2) =3D if h1=3Dh2 then compare x1 x2 else h1-h2 That trick can save a lot of time. Gerd > A customized comparison function stays in ocaml and handles only what > you need ie. it's driven by type information that the generic function > lacks. >=20 >=20 > Yotam >=20 > On Wed, Sep 10, 2014 at 7:27 AM, Gerd Stolpmann > wrote: > Am Mittwoch, den 10.09.2014, 10:56 +0200 schrieb SF Markus > Elfring: > > Hello, > > > > I extended my software development experience a bit for the > programming language > > "OCaml". I find my knowledge incomplete here to resolve an > issue like > > "Comparison function application" alone. > > https://github.com/elfring/OTCL/issues/4 >=20=20=20=20=20=20=20=20=20 > There are three reasons why you want to have your own > comparison > function: >=20=20=20=20=20=20=20=20=20 > - You need a different ordering than provided by > Pervasives.compare. > For compound types the ordering of compare is > implementation-defined, > and currently the implementation prefers the fastest way of > comparing. > E.g. if you compare arrays, you don't get a lexicographic > ordering. > This is sometimes not what you need. > - Your values are cyclic. compare may hang if you try to > compare cyclic > values. > - Your values contains parts that cannot be compared, like > functions. > With a custom comparison function you can skip these parts. >=20=20=20=20=20=20=20=20=20 > Gerd >=20=20=20=20=20=20=20=20=20 > > How do you think about to discuss corresponding > implementation details for an > > evolving class library? > > > > I would appreciate your advices. > > > > Regards, > > Markus > > >=20=20=20=20=20=20=20=20=20 > -- > ------------------------------------------------------------ > Gerd Stolpmann, Darmstadt, Germany gerd@gerd-stolpmann.de > My OCaml site: http://www.camlcity.org > Contact details: http://www.camlcity.org/contact.html > Company homepage: http://www.gerd-stolpmann.de > ------------------------------------------------------------ >=20=20=20=20=20=20=20=20=20 >=20 >=20 --=20 ------------------------------------------------------------ Gerd Stolpmann, Darmstadt, Germany gerd@gerd-stolpmann.de My OCaml site: http://www.camlcity.org Contact details: http://www.camlcity.org/contact.html Company homepage: http://www.gerd-stolpmann.de ------------------------------------------------------------ --=-567b+DNNih4ZKpC/PNqO Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part Content-Transfer-Encoding: 7bit -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQEcBAABAgAGBQJUEEN0AAoJEAaM4b9ZLB5TtHQH/1/fz3o2YEbAKMKiYaNBylyj HT2CrnCUqTcd5AzXXLyAfQhnlPb1LWukP5sYGl6503P33jLRuSkwwBFnyoK2OSLC Xia7+4jnmPmn34khPQ0jmcRmOrM88zl0zDVsYRgGDuSeJY7zEsYMVgzAYBGIXOUI 967U8qTyeW4TX2oiOiqESbEMzMn9ev9phMpfO2C3gcf+eVE+HMqPj3sFl2D78FTK ftyDwTptAsJCkkBvxqdyLIAPYDo2uDIxL934824RNwLhhjqpqHJUe3QnTsum2pS1 jGV3nsQMg8/BnKD9lMoUxsdBKRb7LKASIoZmZol6oPHAvWf8J3dhQcDg4kAVNWw= =+zXm -----END PGP SIGNATURE----- --=-567b+DNNih4ZKpC/PNqO--