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 VAA16394; Wed, 10 Jul 2002 21:22:51 +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 VAA16390 for ; Wed, 10 Jul 2002 21:22:51 +0200 (MET DST) Received: from smtp.noos.fr (aragon.noos.net [212.198.2.75]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g6AJMob13884 for ; Wed, 10 Jul 2002 21:22:50 +0200 (MET DST) Received: (qmail 4335475 invoked by uid 0); 10 Jul 2002 19:22:49 -0000 Received: from unknown (HELO noos.fr) ([81.65.61.57]) (envelope-sender ) by 212.198.2.75 (qmail-ldap-1.03) with SMTP for ; 10 Jul 2002 19:22:49 -0000 Message-ID: <3D2C897D.873E9E0C@noos.fr> Date: Wed, 10 Jul 2002 21:22:38 +0200 From: nadji@noos.fr X-Mailer: Mozilla 4.77 [en] (X11; U; Linux 2.4.18 i686) X-Accept-Language: en MIME-Version: 1.0 To: sebastien FURIC CC: Dave Mason , caml-list@inria.fr Subject: Re: [Caml-list] productivity improvement References: <200207101158.g6ABwVm25582@sarg.ryerson.ca> <3D2C3296.126C83F0@tni.fr> Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk sebastien FURIC wrote: > Dave Mason a écrit : > > > > Further to my comment on benchmarking... > > > > I just ran your ocaml lazy version, and got: > > > > real 14m15.124s > > user 13m26.769s > > sys 0m2.510s > > > ... > > in garbage collection. This looks like a perfect garbage-collector > > stress test! > I did some tests and it seems a lot of time is being spent on garbage collection. > > > > My guess for why Clean does well suggests a garbage collector better > > tuned to the problem, but more importantly, a much more efficient > > handling of laziness. I suspect you'd see similar results for this > > problem in Haskell. Of course that doesn't mean Clean or Haskell will > > beat OCaml at most, or even many, other benchmarks. But when laziness > > is inherent in a solution, expect lazy languages to do much better > > than eager languages. > > ... with a lazy style of programming. I ran your test with my computer, and it took it around 5mn to complete. I programmed the same test in a functional way (and with DDR's syntactic sugar), and it now completes in 21s. Moreover, the program is nearly as short as your Clean one. See below. > It is not very surprising to beat O'Caml using a language that is tuned > to perform lazy computations natively when the problem to solve is lazy! I don't agree with you when you say that the problem to solve is lazy. The _algorithm_ you use is lazy. There are certainly lots of ways to solve it with imperative style, and lots of optimisations (I think of multiprocessor ones) that you can't implement with your algorithm. file erat.ml : (* defines 2 streams : the first one is the functional that I have written, and the second is Sébastien Furic's one *) let primes1 = let rec erat isprime n = if isprime n then [< 'n; erat (fun k -> isprime k && k mod n <> 0) (n + 1) >] else erat isprime (n + 1) in erat (fun _ -> true) 2 let primes2 = let rec filter f = parser [< 'n; xs >] -> if f n then [< 'n; filter f xs >] else filter f xs in let rec sieve = parser [< 'p; xs >] -> [< 'p; sieve (filter (fun x -> x mod p <> 0) xs) >] in let rec from k = [< 'k; from (k + 1) >] in sieve (from 2) let _ = let primes = match Sys.argv.(1) with "1" -> primes1 | "2" -> primes2 | _ -> failwith "syntax: erat (1|2) n" in let rec print_stream = function | 0 -> Printf.printf "\n" | n -> Printf.printf "%d " (Stream.next primes); print_stream (n - 1) in print_stream (int_of_string (Sys.argv.(2))) compile it with : ocamlopt -o erat -pp camlp4o erat.ml on my computer, time ./erat 1 10000 -> 0:21.74 time ./erat 2 10000 -> 5:15.87 Cheers, Nadji ------------------- 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