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 NAA08639; Sat, 3 Jan 2004 13:58:02 +0100 (MET) 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 NAA06704 for ; Sat, 3 Jan 2004 13:58:01 +0100 (MET) Received: from mailer.zkm.de (mailer.zkm.de [193.197.168.42]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id i03Cw0b21952 for ; Sat, 3 Jan 2004 13:58:00 +0100 (MET) Received: from mail.zkm.de (localhost [127.0.0.1]) by mailer.zkm.de (8.12.9/8.12.5) with ESMTP id i03CwFbX027958 for ; Sat, 3 Jan 2004 13:58:16 +0100 (MET) Received: from bild.zkm.de (bifi1.zkm.de [193.197.169.148]) by mail.zkm.de (8.12.9/8.12.9) with SMTP id i03CwBW2027955 for ; Sat, 3 Jan 2004 13:58:12 +0100 (MET) Received: from 80.131.128.216 (SquirrelMail authenticated user dolfi) by bild.zkm.de with HTTP; Sat, 3 Jan 2004 13:57:24 +0100 (CET) Message-ID: <32894.80.131.128.216.1073134644.squirrel@bild.zkm.de> Date: Sat, 3 Jan 2004 13:57:24 +0100 (CET) Subject: [Caml-list] novice puzzled by speed tests From: dolfi@zkm.de To: caml-list@inria.fr User-Agent: SquirrelMail/1.4.0 MIME-Version: 1.0 Content-Type: text/plain;charset=iso-8859-1 X-Priority: 3 Importance: Normal X-Loop: caml-list@inria.fr X-Spam: no; 0.00; zkm:99 toying:01 ocamlopt:01 -unsafe:01 mandrake:01 slower:01 ocamlopt:01 400000:99 toggle:01 psize:01 truncate:01 psize:01 toggle:01 printf:01 printf:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Hi everybody, I'm new to the list, and deeply impressed by the stability and speed of OCaml, as well as its functional nature. My best congratulations to the authors! Toying around with 3.07, I found that ocamlopt.opt -unsafe (on Mandrake 9.1, Pentium 4, 2.4 GHz) actually produces slower code than ocamlopt.opt. The program in question is a prime generator: let count = 400000 let ptab = let ptab = Array.create count 0 in ( ptab.(0)<- 2; ptab.(1) <- 3; ptab.(2) <- 5; ptab );; let rec loop nr toggle psize = ( let max = truncate (sqrt (float nr)) in let rec floop i = if ptab.(i)>max then ( ptab.(psize) <- nr; loop (nr+toggle) (6-toggle) (succ psize) ) else if nr mod ptab.(i) = 0 then loop (nr+toggle) (6-toggle) psize else floop (succ i) in if psize #include #define how_many 400000 int main() { unsigned int nr = 5, toggle = 2, max, primes_size = 3, i; unsigned int primes[how_many]; primes[0] = 2; primes[1] = 3; primes[2] = 5; loop: nr += toggle; toggle = 6 - toggle; max = sqrt(nr); for (i = 2; primes[i] <= max; ++i) if (!(nr % primes[i])) goto loop; primes[primes_size++] = nr; if (primes_size < how_many) goto loop; printf("%i\n", primes[how_many - 1]); return 0; } Of course it's good that range checking increases the speed of programs, but, being a long-time C user, I'm a little bit puzzled by miracles like this. I suspected that the sense of the -unsafe flag was inverted, but it isn't: the -unsafe program dies with SEGV when I deliberately introduce a range overflow, the safe one gets an exception. Till soon, Dolfi ------------------- 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