Browse thread
[Caml-list] what is the functional way to solve this problem?
[
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: | Pierre Weis <weis@p...> |
| Subject: | Re: [Caml-list] what is the functional way to solve this problem? |
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