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 BAA03048; Wed, 20 Nov 2002 01:35:25 +0100 (MET) 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 BAA03652 for ; Wed, 20 Nov 2002 01:35:24 +0100 (MET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id gAK0VKX03239; Wed, 20 Nov 2002 01:31:20 +0100 (MET) Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id BAA03544; Wed, 20 Nov 2002 01:31:19 +0100 (MET) From: Pierre Weis Message-Id: <200211200031.BAA03544@pauillac.inria.fr> Subject: Re: [Caml-list] Even at compile time 2*2=4! In-Reply-To: <3DDA1C68.5070909@baretta.com> from Alessandro Baretta at "Nov 19, 102 12:11:36 pm" To: alex@baretta.com (Alessandro Baretta) Date: Wed, 20 Nov 2002 01:31:19 +0100 (MET) Cc: jl@itu.dk, caml-list@inria.fr X-Mailer: ELM [version 2.4ME+ PL28 (25)] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > Jakob Lichtenberg wrote: > > > > > I wish to package/compile my 'fourLib' so that I can avoid doing the > > complicated calculation '2*2' each and every time I load 'fourLib'. (I am > > sure that you can imagine an even more requiring computational task than > > evaluating '2*2'.) > > I wish to suggest one possibility. > > 1) You write a module defining the type of the datastructure > you wish to precompute and load > 2) You write a program importing the above module, which > computes the datastructure and marshals it to a file. You > run this program. > 3) You write a library which, upon being loaded, searches > the filesystem for the appropriate file, unmarshals it and > binds the precomputed data to an identifier. > 4) You write your programs referring to the the identifier > exported by #3. [...] > Cheers, > Alex I clearly see what you want to do, this is as old as functional programming (remember the old LISP eval-when-compile form). As far as I know people want that feature because they think (well in fact, they say they KNOW for sure) that this will speed up their programs. This is unclear to me. I remember to have read the source code of a CAS, entirely written in Lisp, that started by computing a lot of constants with a huge number of decimals (including $\pi$ and $e$). So, I said "he guys, you could easily speed up your stuff by just defining the pre-calculated constants instead of computing them from scratch again and again at each start of your program!" They politely thanked me for the suggestion, but they had to let me know that they knew from time measurements that this ``presumably enhanced'' method was much slower than re-computation: building the constants directly in memory via computation was much faster than any way they had found to get them stored into the memory at the beginning of the program. Effectively, at launch time the constants have to be read from files and this is really slow ! (The constants written at compile time in the executable are stored to disk anyway and have to be read back when launching the program: in the case of the CAS program, loading those huge constants with the executable was slower than loading a small executable that re-computed them from scratch!) Life is not that simple... Pierre Weis INRIA, Projet Cristal, Pierre.Weis@inria.fr, http://pauillac.inria.fr/~weis/ ------------------- 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