From: "Alexander V. Voinov" <avv@quasar.ipa.nw.ru>
To: Daniel de Rauglaudre <daniel.de_rauglaudre@inria.fr>
Cc: "caml-list@inria.fr" <caml-list@inria.fr>
Subject: Re: [Caml-list] Generation of streams is slow
Date: Fri, 13 Jul 2001 19:51:09 -0700 [thread overview]
Message-ID: <3B4FB39D.10D1F6D5@quasar.ipa.nw.ru> (raw)
In-Reply-To: <20010714042701.A24266@verdot.inria.fr>
[-- Attachment #1: Type: text/plain, Size: 723 bytes --]
Hi Daniel,
Daniel de Rauglaudre wrote:
>
> Hi,
>
> On Fri, Jul 13, 2001 at 03:06:15PM -0700, Alexander V. Voinov wrote:
>
> > I've run the following program and found it to be extremely slow. Why?
>
> To be optimized, streams and parsers must be preprocessed by Camlp4.
> If they are not, their code is longer, not tail recursive and can be
> very very slow indeed.
>
> Compile you file with the option -pp camlp4o.
Yes, the difference is substantial, but it gets longer and longer anyway
with more elements parsed (for a slightly more complex program, which
parses the stream as it is generated) and crashes at some point.
I've attached the program (change parse_stream to parse_stream' and vice
versa).
Alexander
[-- Attachment #2: test_streams.ml --]
[-- Type: text/plain, Size: 1065 bytes --]
open Printf
let gen_stream n =
let rec gs i n =
if i = n then begin
printf "making last element of the stream\n";
flush stdout;
[< 'n >]
end
else begin
if i mod 1000 = 0 then begin
printf "making next element of the stream: %d\n" i;
flush stdout
end;
[< 'i; (gs (i+1) n) >]
end
in
gs 1 n
let rec print_list = function
[] -> printf "[]\n"
| h::t -> printf "%d::" h;
print_list t
let rec parse_stream s =
match s with parser
[< 'i; s' >] -> begin
if i mod 1000 = 0 then begin
printf "picked element %d\n" i;
flush stdout
end;
i::(parse_stream s')
end
| [< >] -> (printf "end\n"; flush stdout; [])
let rec parse_stream' s =
match s with parser
[< 'i; tail = parse_stream' >] -> begin
if i mod 1000 = 0 then begin
printf "picked element %d\n" i;
flush stdout
end;
i::tail
end
| [< >] -> (printf "end\n"; flush stdout; [])
let _ =
print_list (parse_stream' (gen_stream 700000))
next prev parent reply other threads:[~2001-07-14 2:52 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-07-13 22:06 Alexander V. Voinov
2001-07-14 2:27 ` Daniel de Rauglaudre
2001-07-14 2:51 ` Alexander V. Voinov [this message]
2001-07-14 4:04 ` Daniel de Rauglaudre
2001-07-14 4:15 ` Alexander V. Voinov
2001-07-14 4:40 ` Alexander V. Voinov
2001-07-14 8:34 ` Daniel de Rauglaudre
2001-07-14 18:08 ` Alexander V. Voinov
2001-07-14 19:02 ` Daniel de Rauglaudre
2001-07-14 19:51 ` Alexander V. Voinov
2001-07-14 21:59 ` Alexander V. Voinov
2001-07-14 22:29 ` Daniel de Rauglaudre
2001-07-17 2:36 ` Jacques Garrigue
2001-07-14 8:31 ` Daniel de Rauglaudre
2001-07-20 7:49 ` Chris Hecker
2001-07-17 16:01 Dave Berry
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=3B4FB39D.10D1F6D5@quasar.ipa.nw.ru \
--to=avv@quasar.ipa.nw.ru \
--cc=caml-list@inria.fr \
--cc=daniel.de_rauglaudre@inria.fr \
/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