English version
Accueil     Ŕ propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis ŕ jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml ŕ l'adresse ocaml.org.

Browse thread
[Caml-list] ocaml and large development projects
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2003-05-20 (13:21)
From: Michal Moskal <malekith@p...>
Subject: Re: [Caml-list] Reading a file
On Tue, May 20, 2003 at 10:42:44AM +0200, Siegfried Gonzi wrote:
> Hi:
> Is there a better way in Ocaml to read a file line by line than via the 
> read_line function?
> I use read_line on a file, perform some tasks on this line and store the 
> results in a list and after having red the file I use List.rev. The 
> problem actually is on big files the function is awfully slow. As 
> similar Clean function takes 15 seconds, my Bigloo program takes 25 
> second and my C++ programs (via templates) takes 25 secondes but my 
> Ocaml program takes 8 minutes.

> Why my Clean function is that fast is incomprehensible for me. Does one 
> know whether there exists a function in OCaml which converts a String to 
> a character-list? I use this construct in Clean then in order to extract 
> floating point numbers from that character list: ['1','.','2',...] and 
> store this floating point numbers via pattern matching in my result-list.

If you expand each line of megabyte file to list of characters -- it
cannot be fast.

On my box reading 32M file (800k lines) takes 3.4s with List.rev at the
end and 2.8s without. Reading the same file into array takes 2.3s. All
using ocamlopt, x86 linux, glibc 2.3.2. Doing the same thing in C
(using strdup() to remember lines) takes 0.7s (the C program is flawed
in some aspects, so don't take it too seriously).

: Michal Moskal :: http://www.kernel.pl/~malekith : GCS {C,UL}++++$ a? !tv
: PLD Linux ::::::::: Wroclaw University, CS Dept : {E-,w}-- {b++,e}>+++ h

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