Version française
Home     About     Download     Resources     Contact us    
Browse thread
[oliver: Re: [Caml-list] Strings as arrays or lists...]
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Alain.Frisch@e...
Subject: Re: [oliver: Re: [Caml-list] Strings as arrays or lists...]
On Mon, 3 Mar 2003, Issac Trotts wrote:

> Char arrays take up four times as much space as strings, but there is a
> tradeoff
> of space versus time.  The statement
>
>   let a = Array.make 2000000 ' ';;
>
> takes no noticable time, but
>
>   let s = String.make 2000000 ' ';;
>
> takes about 7 seconds to run on my computer.


Oh really ?  I'm interested in your benchmark methodology. Hint: it may
be the case that the pretty-printing of s in the toplevel is slower that
the pretty-printing of a, but this is not relevant, is it ?

As for me, I get:

glouglou ~/tmp $ cat a.ml
let a = Array.make 2000000 ' ';;
glouglou ~/tmp $ time ocaml a.ml
ocaml a.ml  0,16s user 0,01s system 101% cpu 0,167 total
glouglou ~/tmp $ cat s.ml
let s = String.make 2000000 ' ';;
glouglou ~/tmp $ time ocaml s.ml
ocaml s.ml  0,04s user 0,02s system 102% cpu 0,058 total
glouglou ~/tmp $ cat x.ml
glouglou ~/tmp $ time ocaml x.ml
ocaml x.ml  0,03s user 0,01s system 108% cpu 0,037 total

(x.ml is an empty file, to evaluate ocaml toplevel startup time)
Which seems to indicate that String.make is unsurpisingly a lot faster
than Array.make.

-- Alain

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