From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id JAA08253 for caml-redistribution; Thu, 28 Jan 1999 09:20:03 +0100 (MET) 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 GAA11303 for ; Thu, 28 Jan 1999 06:08:30 +0100 (MET) Received: from linc.cis.upenn.edu (LINC.CIS.UPENN.EDU [158.130.12.3]) by nez-perce.inria.fr (8.8.7/8.8.7) with ESMTP id GAA04583 for ; Thu, 28 Jan 1999 06:08:27 +0100 (MET) Received: from codex.cis.upenn.edu (CODEX.CIS.UPENN.EDU [158.130.6.15]) by linc.cis.upenn.edu (8.8.5/8.8.5) with ESMTP id AAA09783 for ; Thu, 28 Jan 1999 00:08:25 -0500 (EST) Received: (from mwh@localhost) by codex.cis.upenn.edu (8.8.5/8.8.5) id AAA21644 for caml-list@inria.fr; Thu, 28 Jan 1999 00:08:24 -0500 (EST) From: Michael Hicks Message-Id: <199901280508.AAA21644@codex.cis.upenn.edu> Subject: one-time initialization To: caml-list@inria.fr Date: Thu, 28 Jan 1999 00:08:23 -0500 (EST) X-Mailer: ELM [version 2.4 PL23-upenn3.1] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: weis I wonder if anyone knows how to optimize the following (simplified for the sake of dicussion) situation: let global = ref None let init i = global := Some i let f () = match (!global) with Some x -> x | None -> failwith "not initialized";; let g() = match (!global) with ... Essentially, there is some global state that is initialized once, and is used by all functions in the module. In a more realistic situation, this state might be initialized by reading in a file. Given that following initialization the global state never changes, it should be conceivable to eliminate the match and dereference; on my machine (pentium 166), the match and dereference result in about a 30% slowdown. I've fooled around with some things, but haven't found anything that performs better than this straightforward approach or is any more elegant. Thanks, Mike -- Michael Hicks Ph.D. Candidate, the University of Pennsylvania http://www.cis.upenn.edu/~mwh mailto://mwh@dsl.cis.upenn.edu "I worked with an individual who plugged his power strip back into itself and for the life of him could not understand why his computer would not turn on."