caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: William Chesters <williamc@paneris.org>
To: caml-list@inria.fr
Subject: Re: [Caml-list] Is anyone using caml for music or sound synthesis?
Date: Fri, 9 Aug 2002 09:50:22 +0100	[thread overview]
Message-ID: <15699.33358.975751.318231@beertje.william.bogus> (raw)
In-Reply-To: <20020809082757.GB4942@fichte.ai.univie.ac.at>

Markus Mottl writes:
 > On Fri, 09 Aug 2002, Nicolas Cannasse wrote:
 > > Yes but such algorithms are making a large use of float calculations, and
 > > ocaml float are boxed into a block, so such calcs could trigger multiples
 > > allocations.
 > 
 > It's true that this can deteriorate performance in the general case,
 > but note that the compiler performs a fair amount of unboxing (e.g.
 > float arrays when the compiler can see the float type). This usually makes
 > numeric code run surprisingly fast in OCaml. If you know the details, you
 > can most often write your code in such a way that it performs efficiently.
 > Then it really isn't much worse than C.

That's been my experience too.  The main "gotcha" is that when you
write imperative loops you should avoid using "float ref", because
the polymorphism of the 'a ref type prevents float unboxing.  Hence
don't do

  let tot = ref 0. in
  for i = 0 to Array.length a do
    tot := !tot +. a.(i)
  done

but rather

  type floatref = { mutable v: float }

  let tot = { v = 0. } in
  for i = 0 to Array.length a do
    tot.v <- tot.v +. a.(i)
  done

The other thing to remember is that ocaml doesn't do inlining across
compilation boundaries.  If you bear those things in mind, though, it
is fine.  You could probably find cases where ocaml did better than
gcc because of the latter's occasional brainstorms when it comes to
register allocation.
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


  reply	other threads:[~2002-08-09  8:47 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-08-08 20:01 Will Benton
2002-08-08 22:36 ` Oleg
2002-08-09  5:18   ` Travis Bemann
2002-08-09  7:42     ` Nicolas Cannasse
2002-08-09  8:27       ` Markus Mottl
2002-08-09  8:50         ` William Chesters [this message]
2002-08-09  9:38           ` Oleg
2002-08-09 13:32   ` Xavier Leroy
2002-08-09 17:01     ` Ken Rose
2002-08-11 20:18 ` Thorsten Ohl

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=15699.33358.975751.318231@beertje.william.bogus \
    --to=williamc@paneris.org \
    --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).