Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] Newbie Ocaml performance questions
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2001-08-06 (02:40)
From: Luke Gorrie <luke@b...>
Subject: [Caml-list] Newbie Ocaml performance questions
G'day all,

As a programming exercise, I've ported an Erlang program to
Ocaml. It's the first caml code I've written, and the program is an
optimiser from the ICFP contest. I was quite pleased to see that most
of the program could be ported line-for-line straight into caml.

Now I'm having a look at the performance, and surprised to see that
the Caml (native) and Erlang ones run at about the same speed. I'm
curious about why this is and whether there are some simple things
that would make the Caml version a lot quicker without changing the
basic style.

The program is almost purely functional and spends its time doing list
traversals - sometimes building things on the stack, sometimes in an
accumulator - and pattern matching.

So I have a few questions:

- Is it reasonable to expect purely functional list-based code to run
  really fast (compared to bytecode interpreted systems like Erlang),
  or does one usually "go imperative" to get speed?
- Is there some common listy/recursive style that is particularly
  slow - e.g. deep recursions building up a stack?
- Is there an easy way to measure the number of milliseconds it takes
  to evaluate a certain expression?

And some miscellaneous:

- How do I print to stdout a text representation of an arbitrary
  object? (Like the way the shell prints results)
- Can I increase the stack size (for native and bytecode)? It seems to
  blow out on me at a depth of about 70,000 in simple functions - I'd
  like to be able to get about 100x deeper.

Thanks for any help! Ocaml is a fun language.

P.S., it's certainly not impossible that I've done something stupid
and ported it too naively, but it looks pretty straight forward.

"It seems possible that some sufficiently inquiring mind (loony) could
find meaning in this." -- Graham Gorrie
Bug reports:  FAQ:
To unsubscribe, mail  Archives: