Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Michal Moskal <malekith@pld-linux.org>
To: Pierre Weis <pierre.weis@inria.fr>
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 18:09:15 +0200	[thread overview]
Message-ID: <20031008160915.GA4730@roke.freak> (raw)
In-Reply-To: <200310081448.QAA14841@pauillac.inria.fr>

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


  reply	other threads:[~2003-10-08 16:10 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
2003-10-08 16:09     ` Michal Moskal [this message]
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=20031008160915.GA4730@roke.freak \
    --to=malekith@pld-linux.org \
    --cc=caml-list@pauillac.inria.fr \
    --cc=pierre.weis@inria.fr \
    --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