Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] what is the functional way to solve this problem?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2003-10-08 (14:48)
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 :: : 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 () =
    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

  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,,

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: