From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id EAA20499; Sat, 14 Jul 2001 04:52:20 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id EAA20491 for ; Sat, 14 Jul 2001 04:52:19 +0200 (MET DST) Received: from str12.sobor.org (adsl-63-198-183-99.dsl.snfc21.pacbell.net [63.198.183.99]) by nez-perce.inria.fr (8.11.1/8.10.0) with ESMTP id f6E2qIj25997; Sat, 14 Jul 2001 04:52:18 +0200 (MET DST) Received: from quasar.ipa.nw.ru (anza.sobor.org [192.168.123.51]) by str12.sobor.org (Postfix) with ESMTP id B43C0AC6D2; Fri, 13 Jul 2001 19:39:05 -0700 (PDT) Message-ID: <3B4FB39D.10D1F6D5@quasar.ipa.nw.ru> Date: Fri, 13 Jul 2001 19:51:09 -0700 From: "Alexander V. Voinov" Organization: Fear of the Lord is the beginning of wisdom X-Mailer: Mozilla 4.75 [en] (Windows NT 5.0; U) X-Accept-Language: en MIME-Version: 1.0 To: Daniel de Rauglaudre Cc: "caml-list@inria.fr" Subject: Re: [Caml-list] Generation of streams is slow References: <3B4F70D7.82E58A91@quasar.ipa.nw.ru> <20010714042701.A24266@verdot.inria.fr> Content-Type: multipart/mixed; boundary="------------8AE30CFF45EF624A3F321161" Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk This is a multi-part message in MIME format. --------------8AE30CFF45EF624A3F321161 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit 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 --------------8AE30CFF45EF624A3F321161 Content-Type: text/plain; charset=us-ascii; name="test_streams.ml" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="test_streams.ml" 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)) --------------8AE30CFF45EF624A3F321161-- ------------------- Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr