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 BEA327EE51 for ; Wed, 24 Apr 2013 12:35:49 +0200 (CEST) Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of ygrekheretix@gmail.com) identity=pra; client-ip=209.85.220.51; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="ygrekheretix@gmail.com"; x-sender="ygrekheretix@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail3-smtp-sop.national.inria.fr: domain of ygrekheretix@gmail.com designates 209.85.220.51 as permitted sender) identity=mailfrom; client-ip=209.85.220.51; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="ygrekheretix@gmail.com"; x-sender="ygrekheretix@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-pa0-f51.google.com) identity=helo; client-ip=209.85.220.51; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="ygrekheretix@gmail.com"; x-sender="postmaster@mail-pa0-f51.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AuIBAMK0d1HRVdwzm2dsb2JhbABRgzy/TxYOAQEBAQEGCwsJFCiCTRkBGx4DEhApFCERAQUBFoggAQMOAZ1wgnKMMIJ7hGMKGScNWYc1AQUMjVmBYIMzA4kNhWJ3gSmGCgGBI44VP4RB X-IPAS-Result: AuIBAMK0d1HRVdwzm2dsb2JhbABRgzy/TxYOAQEBAQEGCwsJFCiCTRkBGx4DEhApFCERAQUBFoggAQMOAZ1wgnKMMIJ7hGMKGScNWYc1AQUMjVmBYIMzA4kNhWJ3gSmGCgGBI44VP4RB X-IronPort-AV: E=Sophos;i="4.87,542,1363129200"; d="ml'?scan'208";a="12045325" Received: from mail-pa0-f51.google.com ([209.85.220.51]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 24 Apr 2013 12:35:48 +0200 Received: by mail-pa0-f51.google.com with SMTP id jh10so1109103pab.10 for ; Wed, 24 Apr 2013 03:35:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:date:from:to:subject:message-id:x-mailer:mime-version :content-type; bh=CqUU4z8dSDE8xLr+fRdTfvujanaVhBUA5H33jpaxzPE=; b=CgUBtdCc0D/meRIjyWss1772IpWg2DgzimsEMd9lrTbZUI6sBOazREs8sQtRVrrqiM 2FH1QO+6ufPD0rb6pxI3douvZb/G7xRTlmfdWrlKR0hyDLx+Z5yDTbwVGxxRWmsOWld4 fVQKqH9N/hitZxXh3knjUh3FXHJi5NYkfsIAOGSxbYsGdjQSpO9qjfZZPmeppMvtluKe ID7Du1imFwTU1/I8f/ZWeG638A4/I8rOz9nNefFiEXViD0qmigKBEA23983kMaEFEeqH FgJnvJLY3GtHxXYE7HW3uDaM7oKPvaAC/7c+uztyrPAiyr++k/Ft4vpDtrXRrYWcZppk DuNA== X-Received: by 10.68.196.1 with SMTP id ii1mr47194876pbc.200.1366799746894; Wed, 24 Apr 2013 03:35:46 -0700 (PDT) Received: from kiwi.local.tld ([182.55.247.28]) by mx.google.com with ESMTPSA id jw10sm2581891pbb.3.2013.04.24.03.35.44 for (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 24 Apr 2013 03:35:45 -0700 (PDT) Date: Wed, 24 Apr 2013 18:35:43 +0800 From: ygrek To: caml-list@inria.fr Message-Id: <20130424183543.e3a4290382f7f9ce7b522a57@gmail.com> X-Mailer: Sylpheed 3.3.0 (GTK+ 2.24.10; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="Multipart=_Wed__24_Apr_2013_18_35_43_+0800_BFN5+siL6Bmyn1/P" Subject: [Caml-list] ackermann microbenchmark strange results This is a multi-part message in MIME format. --Multipart=_Wed__24_Apr_2013_18_35_43_+0800_BFN5+siL6Bmyn1/P Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Hello, Got some time scratching my head over this little puzzle. Consider this bog-standard ackermann code : let rec ack m n = match m, n with | 0,n -> n+1 | m,0 -> ack (m-1) 1 | m,n -> ack (m-1) (ack m (n-1)) in let _ = ack 4 1 () One could also pass m and n as a tuple. Also the call to the actual computation can be a toplevel let or not. All in all 4 variants. Can you predict what will be the performance and what is the difference (if any) in generated code? All code and Makefile is attached. Running `make bench` here consistently gives the following (ack1, ack3 - tuples, ack2, ack4 - curried) : ack1.ml 0:03.85 ack2.ml 0:04.70 ack3.ml 0:04.60 ack4.ml 0:03.85 Tested with 3.12.1 and 4.00.1 (ack4 becomes slower). Moreover, the generated assembly code for the main loop is the same, afaics. The only difference is the initialization of structure fields and the initial call to ack. Please can anybody explain the performance difference? I understand that microbenchmarks are no way the basis to draw performance conclusions upon, but I cannot explain these results to myself in any meaninful way. Please help! :) -- ygrek http://ygrek.org.ua --Multipart=_Wed__24_Apr_2013_18_35_43_+0800_BFN5+siL6Bmyn1/P Content-Type: application/octet-stream; name="ack1.ml" Content-Disposition: attachment; filename="ack1.ml" Content-Transfer-Encoding: base64 bGV0IHJlYyBhY2sgPSBmdW5jdGlvbgogIHwgMCxuIC0+IG4rMQogIHwgbSww IC0+IGFjayAobS0xLCAxKQogIHwgbSxuIC0+IGFjayAobS0xLCBhY2sgKG0s IG4tMSkpCmluIGxldCBfID0gYWNrICg0LCAxKSBpbiAoKQo= --Multipart=_Wed__24_Apr_2013_18_35_43_+0800_BFN5+siL6Bmyn1/P Content-Type: application/octet-stream; name="ack2.ml" Content-Disposition: attachment; filename="ack2.ml" Content-Transfer-Encoding: base64 bGV0IHJlYyBhY2sgbSBuID0KICBtYXRjaCBtLCBuIHdpdGgKICB8IDAsbiAt PiBuKzEKICB8IG0sMCAtPiBhY2sgKG0tMSkgMQogIHwgbSxuIC0+IGFjayAo bS0xKSAoYWNrIG0gKG4tMSkpCmluIGxldCBfID0gYWNrIDQgMSBpbiAoKQo= --Multipart=_Wed__24_Apr_2013_18_35_43_+0800_BFN5+siL6Bmyn1/P Content-Type: application/octet-stream; name="ack3.ml" Content-Disposition: attachment; filename="ack3.ml" Content-Transfer-Encoding: base64 bGV0IHJlYyBhY2sgPSBmdW5jdGlvbgogIHwgMCxuIC0+IG4rMQogIHwgbSww IC0+IGFjayAobS0xLCAxKQogIHwgbSxuIC0+IGFjayAobS0xLCBhY2sgKG0s IG4tMSkpCgpsZXQgXyA9IGFjayAoNCwgMSkK --Multipart=_Wed__24_Apr_2013_18_35_43_+0800_BFN5+siL6Bmyn1/P Content-Type: application/octet-stream; name="ack4.ml" Content-Disposition: attachment; filename="ack4.ml" Content-Transfer-Encoding: base64 bGV0IHJlYyBhY2sgbSBuID0KICBtYXRjaCBtLCBuIHdpdGgKICB8IDAsbiAt PiBuKzEKICB8IG0sMCAtPiBhY2sgKG0tMSkgMQogIHwgbSxuIC0+IGFjayAo bS0xKSAoYWNrIG0gKG4tMSkpCgpsZXQgXyA9IGFjayA0IDEK --Multipart=_Wed__24_Apr_2013_18_35_43_+0800_BFN5+siL6Bmyn1/P Content-Type: application/octet-stream; name="Makefile" Content-Disposition: attachment; filename="Makefile" Content-Transfer-Encoding: base64 CnRhcmdldDogYWNrMSBhY2syIGFjazMgYWNrNCBhY2sxLnMgYWNrMi5zIGFj azMucyBhY2s0LnMKCmFjayUuczogYWNrJS5tbAoJKGNwICQ8IGFjay5tbDsg b2NhbWxvcHQgLVMgLWMgYWNrLm1sOyBtdiBhY2sucyAkQDsgcm0gYWNrLm1s KQoKYWNrJTogYWNrJS5tbAoJb2NhbWxvcHQgLW8gJEAgJDwKCi5QSE9OWToK YmVuY2g6IHRhcmdldAoJJChmb3JlYWNoIGksMSAyIDMgNCxlY2hvIGFjayRp Lm1sOyB0aW1lIC1mICVFIC4vYWNrJGk7IGVjaG87KQoKLlBIT05ZOiBjbGVh bgpjbGVhbjoKCXJtIC1mICoucyBhY2s/ICouY21pICouY214ICoubyAqLm9i aiAqLmV4ZQo= --Multipart=_Wed__24_Apr_2013_18_35_43_+0800_BFN5+siL6Bmyn1/P--