On Mon, 2007-10-08 at 18:04 +0200, Gerd Stolpmann wrote:
I heard that OCaml is particularly slow (and probably
memory-inefficient) when it comes to string manipulation.
No, this is nonsense. Of course, you can slow everything down by using
strings in an inappropriate way, like
let rec concat_list l =
match l with
[] -> ""
| s :: l' -> s ^ concat_list l'
Now Gerd, I would not call the claim nonsense. If you can't
use a data structure in a natural way, I'd say the claim indeed
has some weight.
The example above is ugly because it isn't tail recursive.
If you consider an imperative loop to concat the strings
in an array
let s = ref "" in
for i = 0 to Array.length a do
s := !s ^ a.[i]
done;
then Ocaml is likely to do this slowly. C++ on the other
hand will probably do this faster, especially if you reserve
enough storage first.