caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: John Prevost <j.prevost@gmail.com>
To: caml-list@inria.fr
Subject: Re: [Caml-list] c is 4 times faster than ocaml?
Date: Wed, 4 Aug 2004 03:28:16 -0400	[thread overview]
Message-ID: <d849ad2a040804002840189222@mail.gmail.com> (raw)
In-Reply-To: <36292.60.246.254.84.1091597068.squirrel@www.ivorykite.com>

On Wed, 4 Aug 2004 15:24:28 +1000 (EST), effbiae@ivorykite.com
<effbiae@ivorykite.com> wrote:
> was the C hard to read or the O'Caml?  Any style tips for my caml?

Mmm.  They were both pretty blinding.  For simple Caml style, read
some code that's around.  There's bad style and good style and
inbetween style, but it all pretty much works.

> if i write a c extension that mmaps and msyncs then will the vector
> element assignment become a call rather than a movb (or movl)?  that is,
> is Bigarray a 'special' c extension that ocaml knows how to optimize and
> access just like C or is it a c extension that i can model my C extension
> code on?

The basic idea is that you would take something that you might
otherwise do as a long sequence of calls and turn it into a single
call.  For example, if you're interested in blitting strings (which
are essentially byte arrays) into a Bigarray containing bytes, you
might write a C function that checks the bounds one time, converts the
O'Caml integers to native C integers one time, and then just does the
fastest memory copy it can.  This will turn into a function call, but
since the main idea is mainly just to amortize the necessary overhead
across a larger amount of data, it should be preferable.

> can i specify that an int32 is held in a register or does the compiler do
> this?

I would expect (and I may be mistaken) that if you have an int32 that
is scoped to just a given function or loop, you can expect it to go
into a register (if there are enough registers to go around.)  Or, for
example, when you have a single expression (Int32.add 5l (Int32.mul x
3l)) it's not going to be allocating a box for all of those constants,
nor for an intermediate result.  When in doubt, try it and take a look
at the assembly file from ocamlopt -S to get a feel for how things
work.  Note that I would generally recommend that you only go to these
lengths when you know it's going to be an issue.  And only after
you've actual evidence that the system is indeed not fast enough. 
Your chosen testcase has more necessary overhead than most, mainly
because it's interacting heavily with a datastructure *meant* to
interoperate with C.  On the whole, ocamlopt produces binaries that
are very fast.  Just remember that it does best when you write things
in the most natural way for this language, and that learning what's
natural in O'Caml will take a little exposure.

John.

-------------------
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:[~2004-08-04  7:28 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-08-04  2:39 effbiae
2004-08-04  4:59 ` John Prevost
2004-08-04  5:05   ` John Prevost
2004-08-04  5:24   ` effbiae
2004-08-04  7:28     ` John Prevost [this message]
2004-08-04  8:18       ` [Caml-list] " Jack Andrews
2004-08-04 10:06         ` Mikhail Fedotov
2004-08-04 10:25           ` [Caml-list] " Jack Andrews
2004-08-04 15:38             ` [Caml-list] custom mmap modeled on bigarray Jack Andrews
2004-08-10  5:06               ` Jack Andrews
2004-08-11 14:52                 ` Eric Stokes

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=d849ad2a040804002840189222@mail.gmail.com \
    --to=j.prevost@gmail.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).