From: "Nathaniel Gray" <n8gray@gmail.com>
To: "Alessandro Baretta" <a.baretta@studio.baretta.com>
Cc: Ocaml <caml-list@inria.fr>
Subject: Re: [Caml-list] Question on performance/style issue
Date: Tue, 28 Feb 2006 21:45:51 -0800 [thread overview]
Message-ID: <aee06c9e0602282145p2bf61f88pac55fc1961186d29@mail.gmail.com> (raw)
In-Reply-To: <43FF2BC9.6030503@studio.baretta.com>
On 2/24/06, Alessandro Baretta <a.baretta@studio.baretta.com> wrote:
> I am very fond of the following "duality" operator.
>
> let (++) x f = f x
>
> I use to write complex computations legibly: instead of
> > h(g(f(x)))
> I write
> > x ++ f ++ g ++ h
>
> What is the impact of the this programming style on execution performance?
Looks bad:
================ simpleops.ml =================
let a x = print_string x; x ^ "."
let b x = x ^ x
let c x = "frotz" ^ x
let (++) x f = f x
let test_oper _ =
" Hello!" ++ a ++ b ++ a ++ b ++ c ++ a ++ b ++ c
let test_normal _ =
c (b (a (c (b (a (b (a " Hello!")))))))
let _ = test_oper ()
let _ = test_normal ()
============ end simpleops.ml ============
Compiled on a PPC powerbook with:
ocamlopt.opt -S -c simpleops.ml
============= from simpleops.s =============
.globl _camlSimpleops__test_oper_66
.text
.align 2
_camlSimpleops__test_oper_66:
mflr r0
addi r1, r1, -32
stw r0, 28(r1)
L105:
addis r11, 0, ha16(_camlSimpleops+4)
lwz r4, lo16(_camlSimpleops+4)(r11)
addis r11, 0, ha16(_camlSimpleops)
lwz r5, lo16(_camlSimpleops)(r11)
stw r4, 0(r1)
addis r11, 0, ha16(_camlSimpleops)
lwz r4, lo16(_camlSimpleops)(r11)
addis r11, 0, ha16(_camlSimpleops+4)
lwz r6, lo16(_camlSimpleops+4)(r11)
lwz r27, 0(r4)
addis r11, 0, ha16(_camlSimpleops+8)
lwz r7, lo16(_camlSimpleops+8)(r11)
addis r11, 0, ha16(_camlSimpleops)
lwz r8, lo16(_camlSimpleops)(r11)
addis r11, 0, ha16(_camlSimpleops+4)
lwz r9, lo16(_camlSimpleops+4)(r11)
addis r11, 0, ha16(_camlSimpleops+8)
lwz r10, lo16(_camlSimpleops+8)(r11)
stw r9, 20(r1)
stw r10, 24(r1)
stw r8, 16(r1)
stw r7, 12(r1)
stw r6, 8(r1)
stw r5, 4(r1)
addis r3, 0, ha16(_camlSimpleops__8)
addi r3, r3, lo16(_camlSimpleops__8)
mtctr r27
L106: bctrl
lwz r4, 0(r1)
lwz r25, 0(r4)
mtctr r25
L107: bctrl
lwz r4, 4(r1)
lwz r23, 0(r4)
mtctr r23
L108: bctrl
lwz r4, 8(r1)
lwz r21, 0(r4)
mtctr r21
L109: bctrl
lwz r4, 12(r1)
lwz r19, 0(r4)
mtctr r19
L110: bctrl
lwz r4, 16(r1)
lwz r17, 0(r4)
mtctr r17
L111: bctrl
lwz r4, 20(r1)
lwz r15, 0(r4)
mtctr r15
L112: bctrl
lwz r4, 24(r1)
lwz r10, 0(r4)
mtctr r10
lwz r11, 28(r1)
addi r1, r1, 32
mtlr r11
bctr
=========================================
Compare that with
=========================================
.globl _camlSimpleops__test_normal_67
.text
.align 2
_camlSimpleops__test_normal_67:
mflr r0
addi r1, r1, -16
stw r0, 12(r1)
L113:
addis r3, 0, ha16(_camlSimpleops__7)
addi r3, r3, lo16(_camlSimpleops__7)
L114: bl _camlSimpleops__a_57
mr r4, r3
L115: bl _camlPervasives__$5e_135
L116: bl _camlSimpleops__a_57
mr r4, r3
L117: bl _camlPervasives__$5e_135
L118: bl _camlSimpleops__c_61
L119: bl _camlSimpleops__a_57
mr r4, r3
L120: bl _camlPervasives__$5e_135
lwz r11, 12(r1)
addi r1, r1, 16
mtlr r11
b _camlSimpleops__c_61
============== end simpleops.s =============
So no, it looks like the call to ++ isn't compiled away, at least in
this case. I also tried with -inline 99 and it didn't help, but I
don't know if that's even a valid value for inline.
Cheers,
-n8
--
>>>-- Nathaniel Gray -- Caltech Computer Science ------>
>>>-- Mojave Project -- http://mojave.cs.caltech.edu -->
next prev parent reply other threads:[~2006-03-01 5:45 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-02-24 15:52 Alessandro Baretta
2006-02-24 19:05 ` [Caml-list] " Anil Madhavapeddy
2006-02-24 19:25 ` Alessandro Baretta
2006-02-25 11:14 ` Andrej Bauer
2006-02-27 22:37 ` David M. Cooke
2006-02-27 23:49 ` [Caml-list] " David Brown
2006-02-28 12:02 ` Alessandro Baretta
2006-02-28 12:04 ` [Caml-list] " Alessandro Baretta
2006-03-01 5:45 ` Nathaniel Gray [this message]
2006-03-01 8:34 ` Alessandro Baretta
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=aee06c9e0602282145p2bf61f88pac55fc1961186d29@mail.gmail.com \
--to=n8gray@gmail.com \
--cc=a.baretta@studio.baretta.com \
--cc=caml-list@inria.fr \
/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).