From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id PAA18020; Tue, 20 May 2003 15:21:57 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id PAA18010 for ; Tue, 20 May 2003 15:21:56 +0200 (MET DST) Received: from ep09.kernel.pl (ep09.kernel.pl [212.87.11.162]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id h4KDLZT08205 for ; Tue, 20 May 2003 15:21:36 +0200 (MET DST) Received: (qmail 2962 invoked by uid 566); 20 May 2003 13:21:18 -0000 Date: Tue, 20 May 2003 15:20:32 +0200 From: Michal Moskal To: Siegfried Gonzi Cc: caml-list@inria.fr Subject: Re: [Caml-list] Reading a file Message-ID: <20030520132032.GA9564@roke.freak> References: <4.3.2.7.2.20030517225010.04b748a0@localhost> <4.3.2.7.2.20030519120753.04545700@localhost> <200305201007.17990.wolfgang.mueller2@uni-bayreuth.de> <3EC9EA84.3070404@stud.uni-graz.at> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3EC9EA84.3070404@stud.uni-graz.at> User-Agent: Mutt/1.4.1i X-PGP-Fingerprint: CF89 1B14 11BE 1CC9 2CA3 7497 5E32 69B4 BC71 B4C2 X-AntiVirus: scanned for viruses by AMaViS 0.2.1 (http://amavis.org/) X-Spam: no; 0.00; michal:01 moskal:01 malekith:01 pld-linux:01 caml-list:01 siegfried:01 gonzi:01 bigloo:01 secondes:99 ocamlopt:01 wroclaw:01 kernel:01 ocaml:01 0200,:01 exists:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk 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