caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Mauricio Fernandez <mfp@acm.org>
To: caml-list@inria.fr
Subject: Re: [Caml-list] native vs bytecode
Date: Wed, 6 Aug 2008 23:47:25 +0200	[thread overview]
Message-ID: <20080806214725.GG6952@NANA.localdomain> (raw)
In-Reply-To: <74a4f4670808061258q30513bbdl446240feab3fdc36@mail.gmail.com>

On Wed, Aug 06, 2008 at 03:58:22PM -0400, Ben Aurel wrote:
> hi
> As I try to acquire more knowledge about Ocaml I made a bit of an
> unpleseant discovery today. I always was fascinated by the execution
> performance of Ocaml. But now I've learned, that this is only true for
> native binaries and I'm a little confused now:
> 
> - is it possible to dynamically load native libraries into a native program?
> 
> - is it possible to dynamically load bytecode libraries into a native program?
> 
> - is it possible to dynamically load native libraries into a bytecode program?
> 
> - is it possible to dynamically load bytecode libraries into a bytecode program?

This has already been addressed by Alain Frisch. I'd only add to his answer
that OCaml 3.11 is being released soon (probably later this month):

http://groups.google.com/group/fa.caml/tree/browse_frm/thread/15126f960406e056/531fda06c1da700e?rnum=1&_done=%2Fgroup%2Ffa.caml%2Fbrowse_frm%2Fthread%2F15126f960406e056%3F#doc_e038a89c482c0c68

> - Are there any performance test that shows how bytecode programs
> stack up agains dynamic languages like ruby, perl and python?

I've compared some OCaml bytecode programs to their Ruby equivalents, and have
often found them to be 2 to 5 times faster _if_ you're not using expensive
stdlib functions which are implemented in OCaml in the first case and happen
to be written in C in Ruby's core classes (for instance, Array.sort vs.
Array#sort; the latter is faster unless the comparison function, or #<=>
method, isn't trivial[1]). I also compared OCaml bytecode with Ruby 1.9 using
some simple micro-benchmarks, and found basic functionality (integer
arithmetic, loops, etc.) to be about as fast (not surprising since the
underlying VMs are quite similar for such things).

Still, overall OCaml bytecode can be faster than Ruby 1.9 (which can itself be
substantially faster than 1.8 sometimes) because in the latter method
dispatching is quite expensive, in contrast to OCaml, where you're applying
known functions most of the time. This holds even in Ruby's best case (method
cache hit).

[1] this deficiency is addressed by using an external C function, the same way
Ruby does. Fortunately, there are few such cases: in the stdlib, some Array
operations (copy, sub and some other operations), the above-mentioned sort
functions, and maybe Hashtbl come to mind.

-- 
Mauricio Fernandez  -   http://eigenclass.org


  parent reply	other threads:[~2008-08-06 21:47 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-06 19:58 Ben Aurel
2008-08-06 20:05 ` [Caml-list] " Alain Frisch
2008-08-07  1:24   ` Matt Gushee
2008-08-07 12:46     ` Richard Jones
2008-08-06 20:09 ` Peng Zang
2008-08-07  7:38   ` Ulf Wiger (TN/EAB)
2008-08-06 21:21 ` Richard Jones
2008-08-07 13:02   ` Kuba Ober
2008-08-07 13:13     ` Kuba Ober
2008-08-07 22:12       ` Michael Ekstrand
2008-08-06 21:47 ` Mauricio Fernandez [this message]
2008-08-07  0:34 ` [Caml-list] " Haoyang Wang

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=20080806214725.GG6952@NANA.localdomain \
    --to=mfp@acm.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).