caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Xavier Leroy <xavier.leroy@inria.fr>
To: "Jérôme Marant" <jmarant@free.fr>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Ocaml efficiency
Date: Wed, 24 Apr 2002 14:05:12 +0200	[thread overview]
Message-ID: <20020424140512.A17777@pauillac.inria.fr> (raw)
In-Reply-To: <87k7r2r8j5.fsf@marant.org>; from jmarant@free.fr on Sat, Apr 20, 2002 at 12:03:58PM +0200

>   Some people are sometimes writing or thinking about writing
>   applications in OCaml without knowing it OCaml is suitable
>   for the kind of applications they're writing.
> 
>   So my question is for what kind of applications isn't OCaml
>   suitable for and better written in a lower lever language?

One example is software components that take a low-level view of the
memory (as an untyped collection of bytes or words accessed via
addresses): memory managers, garbage collectors, device drivers, and
to some extent virtual machine interpreters.

Another example is heavy-duty number crunching, either on floats
(simple, brute-force numerical methods on dense matrixes; signal
processing) or integers (cryptography, compression, signal processing).

In both cases, OCaml will not only give you lower performance than
say C, Fortran or assembly, but the OCaml code will not be
cleaner nor easier to write than the C or Fortran code.

Caml becomes interesting again as soon as your application manipulates
higher-level data structures, or performs significant amounts of
dynamic allocation, though.

>   What is the real cost (in CPU) of interfaces to C libraries
>   since some processing have to be performed in order to convert
>   lower level types to Caml types?

You probably need to do your own measurements here, but the cost can
be quite low.  For instance, consider a C function that is the
identity on Caml integers, i.e. it takes a Caml integer, converts it
to a native integer, then back to a Caml integer, and returns this.
One call from OCaml to this function takes approximately 16 cycles
on a Pentium III and 50 cycles on an Alpha 21164.  (The Alpha suffers
from a more expensive Caml/C context switch and a less efficient
branch prediction engine.)

Caml/C conversions on other data types can be more expensive, though.
Still, as long as the C function does some real work (e.g. 1000 cycles
of computation), the overhead of calling it from Caml should be
negligible.

- Xavier Leroy
-------------------
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


  parent reply	other threads:[~2002-04-24 12:05 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-04-20 10:03 Jérôme Marant
2002-04-20 14:51 ` Vitaly Lugovsky
2002-04-20 15:38   ` Jérôme Marant
2002-04-22 19:48     ` Warp
2002-04-23 17:29       ` Jérôme Marant
2002-04-24 12:05 ` Xavier Leroy [this message]
2002-04-24 16:25   ` Jérôme Marant
2002-04-25 16:17   ` Vitaly Lugovsky
2003-02-17 18:03 Vincent Barichard
2003-02-18 21:25 ` Hans Ole Rafaelsen
2003-02-18 21:32 ` Matt Gushee
2003-02-19  0:57   ` Matt Gushee

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=20020424140512.A17777@pauillac.inria.fr \
    --to=xavier.leroy@inria.fr \
    --cc=caml-list@inria.fr \
    --cc=jmarant@free.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).