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 JAA28801; Wed, 4 Aug 2004 09:28:19 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f 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 JAA28846 for ; Wed, 4 Aug 2004 09:28:18 +0200 (MET DST) Received: from mproxy.gmail.com (rproxy.gmail.com [64.233.170.193]) by concorde.inria.fr (8.12.10/8.12.10) with ESMTP id i747SGRM018931 for ; Wed, 4 Aug 2004 09:28:17 +0200 Received: by mproxy.gmail.com with SMTP id 75so175181rnl for ; Wed, 04 Aug 2004 00:28:16 -0700 (PDT) Received: by 10.38.81.54 with SMTP id e54mr683993rnb; Wed, 04 Aug 2004 00:28:16 -0700 (PDT) Message-ID: Date: Wed, 4 Aug 2004 03:28:16 -0400 From: John Prevost To: caml-list@inria.fr Subject: Re: [Caml-list] c is 4 times faster than ocaml? In-Reply-To: <36292.60.246.254.84.1091597068.squirrel@www.ivorykite.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit References: <36002.60.246.254.84.1091587147.squirrel@www.ivorykite.com> <36292.60.246.254.84.1091597068.squirrel@www.ivorykite.com> X-Miltered: at concorde with ID 41109010.002 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; prevost:01 prevost:01 caml-list:01 2004:99 inbetween:99 movl:01 'special':99 model:01 amortize:01 preferable:01 allocating:01 constants:01 ocamlopt:01 interoperate:01 ocamlopt:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Wed, 4 Aug 2004 15:24:28 +1000 (EST), effbiae@ivorykite.com wrote: > was the C hard to read or the O'Caml? Any style tips for my caml? Mmm. They were both pretty blinding. For simple Caml style, read some code that's around. There's bad style and good style and inbetween style, but it all pretty much works. > if i write a c extension that mmaps and msyncs then will the vector > element assignment become a call rather than a movb (or movl)? that is, > is Bigarray a 'special' c extension that ocaml knows how to optimize and > access just like C or is it a c extension that i can model my C extension > code on? The basic idea is that you would take something that you might otherwise do as a long sequence of calls and turn it into a single call. For example, if you're interested in blitting strings (which are essentially byte arrays) into a Bigarray containing bytes, you might write a C function that checks the bounds one time, converts the O'Caml integers to native C integers one time, and then just does the fastest memory copy it can. This will turn into a function call, but since the main idea is mainly just to amortize the necessary overhead across a larger amount of data, it should be preferable. > can i specify that an int32 is held in a register or does the compiler do > this? I would expect (and I may be mistaken) that if you have an int32 that is scoped to just a given function or loop, you can expect it to go into a register (if there are enough registers to go around.) Or, for example, when you have a single expression (Int32.add 5l (Int32.mul x 3l)) it's not going to be allocating a box for all of those constants, nor for an intermediate result. When in doubt, try it and take a look at the assembly file from ocamlopt -S to get a feel for how things work. Note that I would generally recommend that you only go to these lengths when you know it's going to be an issue. And only after you've actual evidence that the system is indeed not fast enough. Your chosen testcase has more necessary overhead than most, mainly because it's interacting heavily with a datastructure *meant* to interoperate with C. On the whole, ocamlopt produces binaries that are very fast. Just remember that it does best when you write things in the most natural way for this language, and that learning what's natural in O'Caml will take a little exposure. John. ------------------- 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