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 DA27880198 for ; Tue, 11 Jul 2017 14:54:41 +0200 (CEST) Authentication-Results: mail2-smtp-roc.national.inria.fr; spf=Pass smtp.pra=simon.cruanes.2007@m4x.org; spf=Pass smtp.mailfrom=SRS0=DnLF=6O=m4x.org=simon.cruanes.2007@bounces.m4x.org; spf=Pass smtp.helo=postmaster@mx1.polytechnique.org Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of simon.cruanes.2007@m4x.org designates 129.104.30.34 as permitted sender) identity=pra; client-ip=129.104.30.34; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="SRS0=DnLF=6O=m4x.org=simon.cruanes.2007@bounces.m4x.org"; x-sender="simon.cruanes.2007@m4x.org"; x-conformance=sidf_compatible; x-record-type="spf2.0" Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of SRS0=DnLF=6O=m4x.org=simon.cruanes.2007@bounces.m4x.org designates 129.104.30.34 as permitted sender) identity=mailfrom; client-ip=129.104.30.34; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="SRS0=DnLF=6O=m4x.org=simon.cruanes.2007@bounces.m4x.org"; x-sender="SRS0=DnLF=6O=m4x.org=simon.cruanes.2007@bounces.m4x.org"; x-conformance=sidf_compatible; x-record-type="spf2.0" Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of postmaster@mx1.polytechnique.org designates 129.104.30.34 as permitted sender) identity=helo; client-ip=129.104.30.34; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="SRS0=DnLF=6O=m4x.org=simon.cruanes.2007@bounces.m4x.org"; x-sender="postmaster@mx1.polytechnique.org"; x-conformance=sidf_compatible; x-record-type="v=spf1" IronPort-PHdr: =?us-ascii?q?9a23=3AkFyo5xzWKwzmUSXXCy+O+j09IxM/srCxBDY+r6Qd?= =?us-ascii?q?2+MeIJqq85mqBkHD//Il1AaPBtSEraocw8Pt8InYEVQa5piAtH1QOLdtbDQizf?= =?us-ascii?q?ssogo7HcSeAlf6JvO5JwYzHcBFSUM3tyrjaRsdF8nxfUDdrWOv5jAOBBr/KRB1?= =?us-ascii?q?JuPoEYLOksi7ze6/9pnRbglSmDaxfa55IQmrownWqsQYm5ZpJLwryhvOrHtIeu?= =?us-ascii?q?BWyn1tKFmOgRvy5dq+8YB6/ShItP0v68BPUaPhf6QlVrNYFygpM3o05MLwqxbO?= =?us-ascii?q?SxaE62YGXWUXlhpIBBXF7A3/U5zsvCb2qvZx1S+HNsDwULs6Wymt771zRRHmiC?= =?us-ascii?q?kJKSM3/mLZisN/kK1UvRCuqBJkzo7bfI2YLuBzcr/HcN8EQ2dKQ8ZfVzZGAoO5?= =?us-ascii?q?d4YBEusBPeNfr4n7ulADswG+BRS2C+Pp1DBInWL90Koh0+QgFAHG2wogE8gSv3?= =?us-ascii?q?TOsdX6LqESXv6uzKXS0znPc+9a1DXm5YjNfR0gruuAXbVqccre0EQiER7OgFuX?= =?us-ascii?q?qYzgJTyV1+INvnCU7+phSeKvi3MnpBprrjezwccsj5HFh4wLxVDZ7iV23p41Jd?= =?us-ascii?q?KgSEJhYN6kFpVQtyacOoBrQc0iW3lltDskxrACo5K3YTQGxZs9yxPRd/CLaYaF?= =?us-ascii?q?7x37WOqMITp0mmhpdbGiixqo7ESs1vfwW8233VtMsyFLiMPDtmoX2BzW8sWHSu?= =?us-ascii?q?Vy/kOm2TuX0gDS5fxILVoslarcL54gwqIwmYQPvkTDGC/2mVz2jLKIeUk+/eio?= =?us-ascii?q?8evnbq3npp+aKYB0lhnzPrkwlsG7G+g0LxQCUmeB9emyyLHv50P0TbpSgv0ziK?= =?us-ascii?q?bZsZTaJcoBpq6+Bg9Yypst5QqiATu6yNkWk38HIlRFdh+fjoXnIknDIPX3APaw?= =?us-ascii?q?mVisly1rx//eM736A5XNK3/DkLH7cblh8U5c1RA8zdZB6JJPEL0NPu7/VlPzud?= =?us-ascii?q?HDFRA5NBG0w+D7B9pjzYMSQ2ePD6CWMa/Itl+I/O0vL/GWZIAJoDb9N+Ql5/n2?= =?us-ascii?q?gHAlg1AdeK2p0YITaHC5BfRmP16UYWHsg9cECWcFpBAyTO3siF2YUD5cfWy+X6?= =?us-ascii?q?wm5mJzNIXzJIPOVo28yJGO2z28ANUCb2RLGhaLF3P5MYmsVPIFaSbUKchkxG8q?= =?us-ascii?q?T7+kHrQg0Bao/CTg1rNhI/GcrjYZsJXlktNv+uTVmAp0r2QsUOyYj3HLSHt7yD?= =?us-ascii?q?BbDwQq1bxy9BQugmyI1rJ11qRV?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A0CmAgBsyWRZhyIeaIFdHgYMGAEFAQsBh?= =?us-ascii?q?BOuaYUKgxuCGCGJCUEWAQEBAQEBAQEBAQESAQEBCgsJCCgvQg6BYyKCRAYnUhA?= =?us-ascii?q?LDhMlDwVJikIFC61LOos2ASIPgyiIUopeAQSBLAEBAYg0lTcIAQGEKoIdgQGMN?= =?us-ascii?q?4JwgQ+OM5VHJgOBODEhMFF1hiOBc4cvAQEB?= X-IPAS-Result: =?us-ascii?q?A0CmAgBsyWRZhyIeaIFdHgYMGAEFAQsBhBOuaYUKgxuCGCG?= =?us-ascii?q?JCUEWAQEBAQEBAQEBAQESAQEBCgsJCCgvQg6BYyKCRAYnUhALDhMlDwVJikIFC?= =?us-ascii?q?61LOos2ASIPgyiIUopeAQSBLAEBAYg0lTcIAQGEKoIdgQGMN4JwgQ+OM5VHJgO?= =?us-ascii?q?BODEhMFF1hiOBc4cvAQEB?= X-IronPort-AV: E=Sophos;i="5.40,346,1496095200"; d="asc'?ml'?scan'208";a="282954633" Received: from mx1.polytechnique.org ([129.104.30.34]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Jul 2017 14:54:41 +0200 Received: from nunchakus.loria.fr (nunchakus.loria.fr [152.81.10.98]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ssl.polytechnique.org (Postfix) with ESMTPSA id 4DEFE5648E3; Tue, 11 Jul 2017 14:54:40 +0200 (CEST) Date: Tue, 11 Jul 2017 14:54:38 +0200 From: Simon Cruanes To: Alexey Egorov Cc: caml users Message-ID: <20170711125438.GP21228@nunchakus.loria.fr> References: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="1Dvf9Qz7hFaodvwE" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.8.3 (2017-05-23) X-AV-Checked: ClamAV using ClamSMTP at svoboda.polytechnique.org (Tue Jul 11 14:54:40 2017 +0200 (CEST)) X-Spam-Flag: No, tests=bogofilter, spamicity=0.000000, queueID=928995648ED X-Org-Mail: simon.cruanes.2007@polytechnique.org Subject: Re: [Caml-list] Optimizing pure-functional streams --1Dvf9Qz7hFaodvwE Content-Type: multipart/mixed; boundary="cjNiBkmi8s9yAE0W" Content-Disposition: inline --cjNiBkmi8s9yAE0W Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hello, Iterators in OCaml have been the topic of many discussions. Another option for fast iterators is https://github.com/c-cube/sequence , which (with flambda) should compile down to loops and tests on this kind of benchmark. With the attached additional file on 4.04.0+flambda, I obtain the following (where sequence is test-seq): $ for i in test-* ; do echo $i ; time ./$i ; done test-c_loop 5000000100000000 ./$i 0.08s user 0.00s system 97% cpu 0.085 total test-f_loop 5000000100000000 ./$i 0.10s user 0.00s system 96% cpu 0.100 total test-loop 5000000100000000 ./$i 0.18s user 0.00s system 97% cpu 0.184 total test-seq 5000000100000000 ./$i 0.11s user 0.00s system 97% cpu 0.113 total test-stream 5000000100000000 ./$i 0.44s user 0.00s system 98% cpu 0.449 total Note that sequence is imperative underneath, but can be safely used as a functional structure. --=20 Simon Cruanes http://weusepgp.info/ key 49AA62B6, fingerprint 949F EB87 8F06 59C6 D7D3 7D8D 4AC0 1D08 49AA 62B6 --cjNiBkmi8s9yAE0W Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="seq.ml" type 'a seq = ('a -> unit) -> unit let enum high k = for i = 1 to high do k i done [@@inline always] let sum s = let n = ref 0 in s (fun x -> n := !n + x); !n [@@inline always] let filter pred seq k = seq (fun x -> if pred x then k x) [@@inline always] let map f seq k = seq (fun x -> k (f x)) [@@inline always] let high = 1000 * 1000 * 100 let res = enum high |> filter (fun x -> x mod 2 = 0) |> map (( * ) 2) |> sum let _ = Printf.printf "%d\n" res --cjNiBkmi8s9yAE0W-- --1Dvf9Qz7hFaodvwE Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEElJ/rh48GWcbX032NSsAdCEmqYrYFAllkyo4ACgkQSsAdCEmq YrYbyRAAjCG1JabWjv3ATEsixcDrU3TUSsWQ0Ta37LZ2eBnsrphxty9r68xXF2rW ppT1xJBOgfaJIhLOnr8IE1GKG9p1miGYAB/1mhcGSxaZJQBgvyWWmJ6AkayYBV3X WiV+B4ruhLx2eAVSuw68mWd/HYKQGuCS7KxLRul1kCZeu9yMzIrcsm0xtgC/uTq/ IhW+Y2cOqhkIE02vWsf30koKZN37vcWXQ6U0PyBZcQGYK6DRzrJ0ZHeJZLgElkzL gTnQ0YbV1UDhAxguxaVlS2CVFSvXIERgXTU9dCMeIE8IEOTWaEbqgYaxqZqnHbyL 3oi6wPGfHHMHPjzI1O8777uutAwxnAMf3kZAIo43LewqFrIbEYdWGySrFIM4Xafz Fb95TxqbQck8rVoM5PQwW6HS/5oAQBzdJPci+HrDj5P4IjSJmtyJysUSLUsqkTGL c+VPnetqX9uC5mkURgNSx4DUmC97fu+h6mBDOGohZ80ZLLgAw4RYQdVDjGB4yEkd XxM3ELudVGQuicfRQn+/426Xe9kqnOHa51nEyYsCFDgcek+4Tp1vNx6l5EIDBdJu ldFhrzKoJC7P5awOySNaTq3ngbtgAJYcHHDzeMduJTgp+jSDFlzQgKUjw32aqOj1 I+16COporLB0+GQOXMI7w6oHeDPoyWZXzQNGj5dVstYSuPVrouo= =CVbL -----END PGP SIGNATURE----- --1Dvf9Qz7hFaodvwE--