From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=AWL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 17F0FBC69 for ; Sat, 10 Feb 2007 17:18:07 +0100 (CET) Received: from pih-relay04.plus.net (pih-relay04.plus.net [212.159.14.131]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id l1AGI6va026429 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NO) for ; Sat, 10 Feb 2007 17:18:06 +0100 Received: from [80.229.56.224] (helo=[10.0.0.5]) by pih-relay04.plus.net with esmtp (Exim) id 1HFuvO-0005lO-0H for caml-list@yquem.inria.fr; Sat, 10 Feb 2007 16:18:06 +0000 From: Jon Harrop Organization: Flying Frog Consultancy Ltd. To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Multiplication of matrix in C and OCaml Date: Sat, 10 Feb 2007 16:11:06 +0000 User-Agent: KMail/1.9.5 References: <45CAF3E2.7020807@univ-paris12.fr> <200702101452.02955.jon@ffconsultancy.com> In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200702101611.06265.jon@ffconsultancy.com> X-Miltered: at concorde with ID 45CDF03E.001 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; ocaml:01 compiler:01 compiler:01 restrictive:01 ocaml:01 iirc:01 gcc:01 gcc:01 flags:01 bug:01 renderer:01 contrib:01 spinning:98 spinning:98 frog:98 On Saturday 10 February 2007 15:51, ls-ocaml-developer-2006@m-e-leypold.de wrote: > Damn. I should have taken '+'. Even for modulo integer arithmetic that still breaks: a+b > a+c when a+c wraps around max_int and becomes negative but a+b does not, then a+b>a+c even though c>b. > Is the compiler allowed to make optimizations according to known > mathematical laws? Provided they are the correct laws, yes. > I've been wondering about similar optimizations for floats, but didn't > get my examples right. The transformtion done by the compiler would of > course be forbidden to increase the error. Yes, which is actually very restrictive. That is why -ffast-math can make C/C++ programs run so much more quickly. In OCaml, -ffast-math has a different purpose (to enable the emission of trig instructions, IIRC) and it exists on x86 and not AMD64 whereas the same flag exists on both platforms for GCC. Incidentally, why is -ffast-math not always enabled on x86 and why isn't it a no-op on AMD64 (rather than causing an "unknown option" error as it does ATM)? > Still: With a certain Gcc version and flags combination the OP saw a > threefold improvement in performance. That in intself is suspicious (I > don't think that this much optimization potential was left in Gcc ...) > and I still would check for optimization errors in this case. Gcc is > not bug free either, so one should test the correctness of the > compiled program first and wether it really does the work it is > supposed to do. Although Frederic is an expert OCaml programmer, it sounds like his C was a little off the mark (having undefined behaviour and allowing arbitrary optimisations as a consequence). Benchmarking is a real can of worms. I've spent a long time trying to benchmark programs and languages and I really think the only feasible way forward is to measure the real time taken to solve real problems. Even this quickly becomes apples and oranges. For example, F# has a concurrent GC and I have a dual core machine, so F# has the advantage that even single threaded programs can exploit both cores when they are allocation intensive. So how am I supposed to compare the performance of the two languages? There is no panacea. In the end I must measure the time taken to perform an important real world task, like spinning a 3D bunny around. Is spinning a bunny serious enough though? If not, maybe I should use a Mandelbrot renderer: http://caml.inria.fr/cgi-bin/hump.en.cgi?contrib=481 -- Dr Jon D Harrop, Flying Frog Consultancy Ltd. OCaml for Scientists http://www.ffconsultancy.com/products/ocaml_for_scientists