Browse thread
[Caml-list] what is the functional way to solve this problem?
-
Ram Bhamidipaty
-
Michal Moskal
-
Pierre Weis
- Michal Moskal
-
Pierre Weis
-
Michal Moskal
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Michal Moskal <malekith@p...> |
| Subject: | Re: [Caml-list] what is the functional way to solve this problem? |
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