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 QAA14947; Wed, 8 Oct 2003 16:48:11 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id QAA14841; Wed, 8 Oct 2003 16:48:09 +0200 (MET DST) From: Pierre Weis Message-Id: <200310081448.QAA14841@pauillac.inria.fr> Subject: Re: [Caml-list] what is the functional way to solve this problem? In-Reply-To: <20031002145327.GA4690@roke.freak> from Michal Moskal at "Oct 2, 103 04:53:27 pm" To: malekith@pld-linux.org (Michal Moskal) Date: Wed, 8 Oct 2003 16:48:09 +0200 (MET DST) Cc: ramb@sonic.net, caml-list@pauillac.inria.fr X-Mailer: ELM [version 2.4ME+ PL28 (25)] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Loop: caml-list@inria.fr X-Spam: no; 0.00; pierre:01 weis:01 weis:01 caml-list:01 michal:01 scanf:01 scanf:01 michal:01 moskal:01 malekith:01 runtime:01 runtime:01 ocamlopt:01 -unsafe:01 -inline:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Hi Michal, [...] > Key points of my implementation: [...] > 3. It doesn't use Scanf. For such linear task as this Scanf takes 10 or > more times to parse input then actual computations. [...] > -- > : Michal Moskal :: http://www.kernel.pl/~malekith : GCS {C,UL}++++$ a? !tv > : When in doubt, use brute force. -- Ken Thompson : {E-,w}-- {b++,e}>+++ h I'm sorry to report that I was so puzzled by your number 3) key point, that I tested your code and a ``purely scanf'' version to see this ``10 or more times to parse'' behaviour; I didn't notice any runtime difference between the two (native code compiled) versions. Am I missing something ? Could you please try to use the following version of your read function, and report the runtime difference between your hand written code ? (BTW, I compiled the 2 programs using ocamlopt -unsafe -inline 9) let read () = try Scanf.bscanf Scanf.Scanning.stdib " %c" (function | 'D' -> Scanf.bscanf Scanf.Scanning.stdib " %d %d %s" (fun x y s -> D (x, y, s)) | 'F' -> Scanf.bscanf Scanf.Scanning.stdib " %d %s" (fun x s -> F (x, s)) | _ -> invalid_arg "read") with End_of_file -> Eof You should also replace (* let l = read_line () in let (dh, fh) = Scanf.sscanf l "R 0 %[^\n]" start in *) by let (dh, fh) = Scanf.bscanf Scanf.Scanning.stdib "R 0 %s@\n" start in Looking forward for reading from you, Pierre Weis INRIA, Projet Cristal, Pierre.Weis@inria.fr, http://pauillac.inria.fr/~weis/ ------------------- 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