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] Generation of streams is slow
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2001-07-13 (22:05)
From: Alexander V. Voinov <avv@q...>
Subject: [Caml-list] Generation of streams is slow
Hi All,

I've run the following program and found it to be extremely slow. Why?
Does it mean that streams are worth using only when they are built from
input text channels, and in all other cases they are just a waste of


open Printf

let gen_stream n =
  let rec gs i n =
    if i = n then [< 'n >] else [< 'i; (gs (i+1) n) >]
  gs 1 n

let rec stupid_loop n s =
  if n > 0 then begin
    if n mod 1000 = 0 then (print_char('.'); flush stdout);
    let i = s in
    if i <> n then raise (Failure "they don't match");
    stupid_loop (n+1) s
  else 0;;

let _ =
  stupid_loop 1 (gen_stream 100000);;

Bug reports:  FAQ:
To unsubscribe, mail  Archives: