Version française
Home     About     Download     Resources     Contact us    
Browse thread
native vs bytecode
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Mauricio Fernandez <mfp@a...>
Subject: Re: [Caml-list] native vs bytecode
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