From: "Gerd Stolpmann" <info@gerd-stolpmann.de>
To: "Andries Hekstra" <andries.hekstra@philips.com>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Comments welcomed to progr. style / speed of my first ocaml program "Error correcting LDPC decoder"
Date: Thu, 15 Dec 2005 13:03:00 +0100 (CET) [thread overview]
Message-ID: <3943.192.168.1.2.1134648180.squirrel@gps.dynxs.de> (raw)
In-Reply-To: <OFB50A01B3.ECDA5A94-ONC12570D8.00394FEA-C12570D8.003A2427@philips.com >
Andries Hekstra said:
> Attached please find the first program I wrote. It has about the same
> speed as its C++ counterpart (slightly faster). I welcome comments w.r.t.
> programming style, esp. when it affects the speed of the program.
As you are doing a lot of array manipulation, this tip may increase
performance significantly: because "float array" is stored with a
different layout than all other arrays, the compiler generates a dynamic
check for every access when the type of the array elements cannot be
statically determined. For example, your function
let swapElement i j a = let x = a.(i) in a.(i) <- a.(j); a.(j) <- x
is polymorphic in the element type. If you define instead
let swapFloatElement i j (a : float array) =
let x = a.(i) in a.(i) <- a.(j); a.(j) <- x
better code is generated because the mentioned check can be omitted by the
compiler. This applies only if the function is not inlined; swapElement
could be small enough (but qsort, for instance, is definitely not).
Unfortunately, one cannot define swapNonFloatElement because there is no
way to constrain a type that it is not float. So the type system cannot
represent this duality float/non-float, and one must fall back to as many
definitions as element types are actually used.
Gerd
------------------------------------------------------------
Gerd Stolpmann * Viktoriastr. 45 * 64293 Darmstadt * Germany
gerd@gerd-stolpmann.de http://www.gerd-stolpmann.de
------------------------------------------------------------
next prev parent reply other threads:[~2005-12-15 12:03 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-12-15 10:33 Andries Hekstra
[not found] ` <OFB50A01B3.ECDA5A94-ONC12570D8.00394FEA-C12570D8.003A2427@philips.com >
2005-12-15 12:03 ` Gerd Stolpmann [this message]
2005-12-15 12:40 ` [Caml-list] " Gerd Stolpmann
2005-12-15 15:09 ` Xavier Leroy
2005-12-16 19:35 ` Jon Harrop
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=3943.192.168.1.2.1134648180.squirrel@gps.dynxs.de \
--to=info@gerd-stolpmann.de \
--cc=andries.hekstra@philips.com \
--cc=caml-list@yquem.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