caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Anthony Tavener <anthony.tavener@gmail.com>
To: Alain Frisch <alain@frisch.fr>
Cc: John Carr <jfc@mit.edu>, ygrek <ygrekheretix@gmail.com>,
	 "caml-list@inria.fr" <caml-list@inria.fr>
Subject: Re: [Caml-list] ackermann microbenchmark strange results
Date: Wed, 24 Apr 2013 10:57:38 -0600	[thread overview]
Message-ID: <CAN=ouMRu1G2UXfSC0+t7o0VvXaBs-Xy+qDRBaJdxx-Q=7ZVViA@mail.gmail.com> (raw)
In-Reply-To: <51780360.3020607@frisch.fr>

[-- Attachment #1: Type: text/plain, Size: 1328 bytes --]

Ackermann function! That's a familiar beast, but I only thought I knew it
by name (heard of it, never "saw" it). Now that I see it, it was part of a
puzzle that I extracted from asm, translated into OCaml, converted to a
recursive loop without global state... and ended up with almost exactly
that definition. I tried optimizing it for a day... and my notes look like
the Wikipedia page, now that I know what to look for. The challenge
involved computing A(4,1,p), discovering 'p' which results in '6'
(word-wrapped on a 15-bit virtual machine). Eventually I gave up on
reducing or optimizing and memoized... churning through over 20k values of
'p' in less than an hour to find my answer.

I get slightly different, but very consistent, timing (OCaml 4.00.0). In
particular, the timing of ack1 and ack3 are "toggled" compared to yours:

ack1.ml
0:04.89

ack2.ml
0:04.89

ack3.ml
0:03.98

ack4.ml
0:03.98

ack5.ml
0:05.23

I'd also expect this kind of result due to alignment.

And for fun I added ack5, which is the non-match implementation I ended up
deriving from some disassembly:

let test r7 =
  let rec loop x y =
    if x = 0 then y+1
    else if y = 0 then loop (x-1) r7
    else loop (x-1) (loop x (y-1))
  in loop 4 1
let _ = test 1

I didn't compare asm outputs, but looks like this version adds a small
"something".

[-- Attachment #2: Type: text/html, Size: 2034 bytes --]

  reply	other threads:[~2013-04-24 16:57 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-24 10:35 ygrek
2013-04-24 15:57 ` John Carr
2013-04-24 16:08   ` Alain Frisch
2013-04-24 16:57     ` Anthony Tavener [this message]
2013-04-24 17:26     ` rixed
2013-04-24 17:31       ` Török Edwin
2013-04-24 17:35   ` Matteo Frigo
2013-04-26  3:31   ` ygrek
2013-04-24 17:40 ` Xavier Leroy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAN=ouMRu1G2UXfSC0+t7o0VvXaBs-Xy+qDRBaJdxx-Q=7ZVViA@mail.gmail.com' \
    --to=anthony.tavener@gmail.com \
    --cc=alain@frisch.fr \
    --cc=caml-list@inria.fr \
    --cc=jfc@mit.edu \
    --cc=ygrekheretix@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).