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 TAA02996; Thu, 11 Jul 2002 19:03:26 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id TAA02982 for caml-list@pauillac.inria.fr; Thu, 11 Jul 2002 19:03:25 +0200 (MET DST) Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id HAA24321 for ; Thu, 11 Jul 2002 07:53:21 +0200 (MET DST) Received: from gnome06.net.rol.ru (gnome06.net.rol.ru [194.67.1.187]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g6B5rKD23027 for ; Thu, 11 Jul 2002 07:53:20 +0200 (MET DST) Received: from ts1-a187.Spb.dial.rol.ru ([195.190.98.187]:2946 "HELO there" ident: "NO-IDENT-SERVICE[2]" whoson: "-unregistered-" smtp-auth: TLS-CIPHER: TLS-PEER: ) by gnome06.net.rol.ru with SMTP id ; Thu, 11 Jul 2002 09:53:19 +0400 Content-Type: text/plain; charset="koi8-r" From: "Anton E. Moscal" To: Markus Mottl Subject: Re: Sieve of Eratosthenes Performance: various languages (Re: [Caml-list] productivity improvement) Date: Thu, 11 Jul 2002 09:53:05 +0400 X-Mailer: KMail [version 1.3.1] Cc: caml-list@inria.fr References: <20020709182022.69599.qmail@web10706.mail.yahoo.com> <200207102014.QAA14544@dewberry.cc.columbia.edu> <20020710204859.GC18091@fichte.ai.univie.ac.at> In-Reply-To: <20020710204859.GC18091@fichte.ai.univie.ac.at> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-Id: <20020711055319Z3989493-14320+14451@gnome06.net.rol.ru> Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk 11 éÀÌØ 2002 00:48, Markus Mottl wrote: > Compiled to native code (-unsafe -noassert): > > real 0m0.207s > user 0m0.100s > sys 0m0.020s Really the main part of the time spent in console output: with redirection stdout to /dev/null on PIII-630: real 0m0.128s user 0m0.080s sys 0m0.000s Without any output: real 0m0.049s user 0m0.050s sys 0m0.000s The more intersing point is that the straightforward version of this algorithm works only slightly slower than yours: let prime_n' n = let rec gen cnt primes buffer = function | _ when cnt = n -> primes @ List.rev buffer | n' -> let rec test primes buffer = function | p::_ when p*p > n' -> (primes, buffer, true) | p::_ when n' mod p = 0 -> (primes, buffer, false) | _::tl -> test primes buffer tl | [] -> let nxt = List.rev buffer in test (primes @ nxt) [] nxt in let (primes, buffer, res) = test primes buffer primes in if res then gen (cnt + 1) primes (n'::buffer) (n'+ 2) else gen cnt primes buffer (n'+2) in gen 1 [2] [] 3 without any output and count=200000 on PIII/630 timings is the following: yours - 2'83" my - 3'38". Regards, Anton ------------------- 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