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 MAA09521; Tue, 20 May 2003 12:21:18 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id MAA09509 for ; Tue, 20 May 2003 12:21:17 +0200 (MET DST) X-SPAM-Warning: Sending machine is listed in blackholes.five-ten-sg.com Received: from mailf.telia.com (mailf.telia.com [194.22.194.25]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id h4KALFH25053 for ; Tue, 20 May 2003 12:21:15 +0200 (MET DST) Received: from d1o849.telia.com (d1o849.telia.com [213.66.248.241]) by mailf.telia.com (8.12.9/8.12.9) with ESMTP id h4KALEN1004348; Tue, 20 May 2003 12:21:14 +0200 (CEST) X-Original-Recipient: caml-list@inria.fr Received: from gateway (h199n1fls34o849.telia.com [213.67.121.199]) by d1o849.telia.com (8.10.2p2/8.10.1) with ESMTP id h4KALED20309; Tue, 20 May 2003 12:21:14 +0200 (CEST) From: "Mattias Waldau" To: "'Siegfried Gonzi'" , Subject: RE: [Caml-list] Reading a file Date: Tue, 20 May 2003 12:21:10 +0200 Message-ID: <020c01c31eb9$8c376710$0200a8c0@gateway> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook, Build 10.0.3416 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 Importance: Normal In-Reply-To: <3EC9EA84.3070404@stud.uni-graz.at> X-Spam: no; 0.00; mattias:01 waldau:01 caml-list:01 siegfried:01 gonzi:01 bigloo:01 secondes:99 bug:01 faq:01 beginner's:01 beginners:01 bin:01 caml-bugs:01 ocaml:01 caml:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk If the files are not of megabyte size, I just read them into a string. Very fast. (** return the contents of filename as a string *) let read_as_string filename = (* read at most len chars into string s, return the number of chars read *) let rec my_input ic s ofs len = if len <= 0 then ofs else begin let r = input ic s ofs len in if r = 0 then ofs else my_input ic s (ofs+r) (len-r) end in let ic = open_in_bin filename in let max_size = in_channel_length ic in let buf = String.create max_size in let read_chars = my_input ic buf 0 max_size in close_in ic; String.sub buf 0 read_chars ;; > -----Original Message----- > From: owner-caml-list@pauillac.inria.fr > [mailto:owner-caml-list@pauillac.inria.fr] On Behalf Of > Siegfried Gonzi > Sent: den 20 maj 2003 10:43 > To: 'caml-list@inria.fr' > Subject: [Caml-list] Reading a file > > > 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. > > I am not sure how quick List.rev actually is? In Bigloo > reversing a list > has more or less no overhead. My Bigloo function is similar > to my OCaml > function. Could it be that OCaml is that slow because I use "try and > with" constructs in order to check for the end of a file? > > 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. > > S. Gonzi > > > > > > > > > > ------------------- > 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 ------------------- 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