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 SAA12596; Wed, 8 Oct 2003 18:10:14 +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 SAA19766 for ; Wed, 8 Oct 2003 18:10:13 +0200 (MET DST) Received: from nemerle.org (lilith.ii.uni.wroc.pl [156.17.4.7]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id h98GAC104089 for ; Wed, 8 Oct 2003 18:10:12 +0200 (MET DST) Received: from malekith by nemerle.org with local (Exim 4.24) id 1A7Gt4-0007kX-KX; Wed, 08 Oct 2003 18:10:07 +0200 Date: Wed, 8 Oct 2003 18:09:15 +0200 From: Michal Moskal To: Pierre Weis Cc: ramb@sonic.net, caml-list@pauillac.inria.fr Subject: Re: [Caml-list] what is the functional way to solve this problem? Message-ID: <20031008160915.GA4730@roke.freak> Mail-Followup-To: Pierre Weis , ramb@sonic.net, caml-list@pauillac.inria.fr References: <20031002145327.GA4690@roke.freak> <200310081448.QAA14841@pauillac.inria.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <200310081448.QAA14841@pauillac.inria.fr> User-Agent: Mutt/1.4.1i X-PGP-Fingerprint: CF89 1B14 11BE 1CC9 2CA3 7497 5E32 69B4 BC71 B4C2 X-Loop: caml-list@inria.fr X-Spam: no; 0.00; michal:01 moskal:01 malekith:01 pld-linux:01 caml-list:01 pierre:01 weis:01 michal:01 scanf:01 scanf:01 moskal:01 malekith:01 runtime:01 slower:01 -rw-r--r--:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Wed, Oct 08, 2003 at 04:48:09PM +0200, Pierre Weis wrote: > 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 ? Hm, with your version it's only 3 times slower: -rw-r--r-- 1 malekith users 1909887 Oct 8 18:02 /shm/d2 ./statsf < /shm/d2 > /dev/null 0.31s user 0.01s system 103% cpu 0.308 total ./stats < /shm/d2 > /dev/null 0.10s user 0.00s system 155% cpu 0.064 total However, your code is not correct: > 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" ----------------------------------------------------^^ It should be [^\n], as filenames can contain spaces. In this case: ./statsf < /shm/d2 > /dev/null 1.56s user 0.04s system 96% cpu 1.654 total Well, it's 15 times slower. All tests were run on athlon 1.56GHz, under pld-linux, ocaml 3.07, ocamlopt -unsafe -inline 9. -- : 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 ------------------- 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