<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE message PUBLIC
  "-//MLarc//DTD MLarc output files//EN"
  "../../mlarc.dtd"[
  <!ATTLIST message
    listname CDATA #REQUIRED
    title CDATA #REQUIRED
  >
]>

  <?xml-stylesheet href="../../mlarc.xsl" type="text/xsl"?>


<message 
  url="2003/10/899d22452db6890e8647fbc2d53d9ee4"
  from="Michal Moskal &lt;malekith@p...&gt;"
  author="Michal Moskal"
  date="2003-10-08T16:10:14"
  subject="Re: [Caml-list] what is the functional way to solve this problem?"
  prev="2003/10/fe9eb2aaab78d81d8a7bbe3b3ba36dc7"
  next="2003/10/ee34acd3dffbe03f80f49fb59152a170"
  prev-in-thread="2003/10/7f88e86b9d298b383d73b6b58f84f6fb"
  next-in-thread="2003/10/f0d7a9095f1a80f5d23897d58bf50d50"
  prev-thread="2003/10/261f050dccf87201bc913df1d656bf10"
  next-thread="2003/10/9a4a4be0cfe7c019ae4f42aaf4c47b30"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="[Caml-list] what is the functional way to solve this problem?">
<msg 
  url="2003/10/af98552ca0ffbadca25a0ba23600da76"
  from="Ram Bhamidipaty &lt;ramb@s...&gt;"
  author="Ram Bhamidipaty"
  date="2003-10-02T12:41:52"
  subject="[Caml-list] what is the functional way to solve this problem?">
<msg 
  url="2003/10/01f8985812016e242ddd8d73bc92ef59"
  from="Michal Moskal &lt;malekith@p...&gt;"
  author="Michal Moskal"
  date="2003-10-02T14:55:22"
  subject="Re: [Caml-list] what is the functional way to solve this problem?">
<msg 
  url="2003/10/7f88e86b9d298b383d73b6b58f84f6fb"
  from="Pierre Weis &lt;weis@p...&gt;"
  author="Pierre Weis"
  date="2003-10-08T14:48:11"
  subject="Re: [Caml-list] what is the functional way to solve this problem?">
<msg 
  url="2003/10/899d22452db6890e8647fbc2d53d9ee4"
  from="Michal Moskal &lt;malekith@p...&gt;"
  author="Michal Moskal"
  date="2003-10-08T16:10:14"
  subject="Re: [Caml-list] what is the functional way to solve this problem?">
<msg 
  url="2003/10/f0d7a9095f1a80f5d23897d58bf50d50"
  from="Pierre Weis &lt;weis@p...&gt;"
  author="Pierre Weis"
  date="2003-10-08T20:34:41"
  subject="Re: [Caml-list] what is the functional way to solve this problem?">
<msg 
  url="2003/10/0ee5858b073f26c4cbcaef3bc64f2a02"
  from="Michal Moskal &lt;malekith@p...&gt;"
  author="Michal Moskal"
  date="2003-10-08T21:25:11"
  subject="scanf (Re: [Caml-list] what is the functional way to solve this problem?)">
</msg>
</msg>
</msg>
</msg>
</msg>
</msg>
</thread>

<contents>
On Wed, Oct 08, 2003 at 04:48:09PM +0200, Pierre Weis wrote:
&gt; Hi Michal,
&gt; 
&gt; [...]
&gt; &gt; Key points of my implementation:
&gt; [...]
&gt; &gt; 3. It doesn't use Scanf. For such linear task as this Scanf takes 10 or
&gt; &gt;    more times to parse input then actual computations.
&gt; [...]
&gt; &gt; -- 
&gt; &gt; : Michal Moskal :: http://www.kernel.pl/~malekith : GCS {C,UL}++++$ a? !tv
&gt; &gt; : When in doubt, use brute force. -- Ken Thompson : {E-,w}-- {b++,e}&gt;+++ h
&gt; 
&gt; I'm sorry to report that I was so puzzled by your number 3) key point,
&gt; that I tested your code and a ``purely scanf'' version to see this
&gt; ``10 or more times to parse'' behaviour; I didn't notice any runtime
&gt; difference between the two (native code compiled) versions. Am I
&gt; 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 &lt; /shm/d2 &gt; /dev/null  0.31s user 0.01s system 103% cpu 0.308
total
./stats &lt; /shm/d2 &gt; /dev/null  0.10s user 0.00s system 155% cpu 0.064
total

However, your code is not correct:

&gt; Could you please try to use the following version of your read
&gt; function, and report the runtime difference between your hand written
&gt; code ?
&gt; 
&gt; (BTW, I compiled the 2 programs using ocamlopt -unsafe -inline 9)
&gt; 
&gt; let read () =
&gt;   try
&gt;     Scanf.bscanf Scanf.Scanning.stdib " %c" (function
&gt;     | 'D' -&gt;
&gt;         Scanf.bscanf Scanf.Scanning.stdib " %d %d %s"
----------------------------------------------------^^

It should be [^\n], as filenames can contain spaces. In this case:

./statsf &lt; /shm/d2 &gt; /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}&gt;+++ 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

</contents>

</message>

