From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Delivered-To: caml-list@yquem.inria.fr Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id C0989BC75 for ; Fri, 25 Feb 2005 18:07:02 +0100 (CET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j1PH72bD021302 for ; Fri, 25 Feb 2005 18:07:02 +0100 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 SAA18820 for ; Fri, 25 Feb 2005 18:07:02 +0100 (MET) Received: from biscayne-one-station.mit.edu (BISCAYNE-ONE-STATION.MIT.EDU [18.7.7.80]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j1PH70KO021297 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Fri, 25 Feb 2005 18:07:01 +0100 Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103]) by biscayne-one-station.mit.edu (8.12.4/8.9.2) with ESMTP id j1PH6xJj021421 for ; Fri, 25 Feb 2005 12:06:59 -0500 (EST) Received: from mass-toolpike.mit.edu (MASS-TOOLPIKE.MIT.EDU [18.7.16.71]) (authenticated bits=56) (User authenticated as jfc@ATHENA.MIT.EDU) by outgoing.mit.edu (8.12.4/8.12.4) with ESMTP id j1PH6q0b022204 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT) for ; Fri, 25 Feb 2005 12:06:53 -0500 (EST) Received: (from jfc@localhost) by mass-toolpike.mit.edu (8.12.9) id j1PH6qci027710; Fri, 25 Feb 2005 12:06:52 -0500 (EST) Message-Id: <200502251706.j1PH6qci027710@mass-toolpike.mit.edu> To: caml-list@inria.fr Subject: Re: [Caml-list] NBody (one more question) In-Reply-To: Your message of "Thu, 24 Feb 2005 23:18:55 +0100." <20050224.231855.40627447.debian00@tiscali.be> Date: Fri, 25 Feb 2005 12:06:52 -0500 From: John Carr X-Scanned-By: MIMEDefang 2.42 X-Miltered: at nez-perce with ID 421F5B36.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at nez-perce with ID 421F5B34.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 jfc:01 gcc:01 gcc:01 -wall:01 -lm:01 ocaml:01 -wall:01 -lm:01 ocaml:01 ocamlopt:01 ocamlopt:01 replacing:01 compile:01 functional:02 X-Spam-Checker-Version: SpamAssassin 3.0.2 (2004-11-16) on yquem.inria.fr X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.2 X-Spam-Level: > When I compile the C code with -O0 (with gcc -o nbody.gcc -Wall > --fast-math nbody.c -lm), I get a time of 1.513s which is comparable > to OCaml (1.607s). But as soon as I turn on -O options (as with gcc > -o nbody.gcc -Wall -O1 --fast-math nbody.c -lm), the running time > drops down to 0.871s (0.58%). Can somebody tell me what is the > optimization that has such an effect and whether it could be applied > to OCaml ? gcc -O0 sets out to generate the worst possible code, and mostly succeeds. Optimizations in gcc -O1 compared to gcc -O0 include register allocation, dead code elimination, branch straightening, common subexpression elimination, instruction combining, and instruction scheduling. ocamlopt-generated code is between -O0 and -O1 in quality, usually much closer to -O1. The biggest missing optimization is common subexpression elimination. ocamlopt puts less effort into instruction combining than gcc. gcc -O2 adds loop optimizations which ocamlopt never does. A functional programming style puts different demands on the optimizer. ocamlopt has some optimizations that don't make sense for C, e.g. replacing (unbox (box (value))) with value.