From: Pierre Weis <weis@pauillac.inria.fr>
To: malekith@pld-linux.org (Michal Moskal)
Cc: ramb@sonic.net, caml-list@pauillac.inria.fr
Subject: Re: [Caml-list] what is the functional way to solve this problem?
Date: Wed, 8 Oct 2003 16:48:09 +0200 (MET DST) [thread overview]
Message-ID: <200310081448.QAA14841@pauillac.inria.fr> (raw)
In-Reply-To: <20031002145327.GA4690@roke.freak> from Michal Moskal at "Oct 2, 103 04:53:27 pm"
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
next prev parent reply other threads:[~2003-10-08 14:48 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-10-02 12:31 Ram Bhamidipaty
2003-10-02 14:53 ` Michal Moskal
2003-10-08 14:48 ` Pierre Weis [this message]
2003-10-08 16:09 ` Michal Moskal
2003-10-08 20:34 ` Pierre Weis
2003-10-08 21:22 ` scanf (Re: [Caml-list] what is the functional way to solve this problem?) Michal Moskal
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200310081448.QAA14841@pauillac.inria.fr \
--to=weis@pauillac.inria.fr \
--cc=caml-list@pauillac.inria.fr \
--cc=malekith@pld-linux.org \
--cc=ramb@sonic.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox