From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,400766bdbcd86f7c X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!o13g2000cwo.googlegroups.com!not-for-mail From: "Per Lindquist" Newsgroups: comp.lang.ada Subject: Re: This can't be done in Ada...or? Date: 15 Feb 2005 08:30:23 -0800 Organization: http://groups.google.com Message-ID: <1108485023.838467.131230@o13g2000cwo.googlegroups.com> References: <1108139611.709714.36170@o13g2000cwo.googlegroups.com> <2IcPd.6268$mG6.1474@newsread1.news.pas.earthlink.net> <1108372232.436036.318690@g14g2000cwa.googlegroups.com> <1108456053.837461.20340@f14g2000cwb.googlegroups.com> NNTP-Posting-Host: 138.14.239.132 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: posting.google.com 1108485028 10681 127.0.0.1 (15 Feb 2005 16:30:28 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 15 Feb 2005 16:30:28 +0000 (UTC) User-Agent: G2/0.2 Complaints-To: groups-abuse@google.com Injection-Info: o13g2000cwo.googlegroups.com; posting-host=138.14.239.132; posting-account=e84-wQ0AAADeDLnjH5yWqnRMVsJLfQJg Xref: g2news1.google.com comp.lang.ada:8338 Date: 2005-02-15T08:30:23-08:00 List-Id: Robert A Duff wrote: > No, instantiation is a compile-time concept. I'm not sure what > it would mean to delay it until run time. > > The issue here is the cost of running the elaboration code of the > instance. Theoretically, the compiler could optimize it away in this > case, but I don't think any Ada compilers are that smart. The only > way to know for sure is to try it. > > This Reflection package has a bunch of string manipulation code, > and if you instantiate it in a procedure, it will happen > every time that procedure is called (unless the compiler > is smarter than I think it is). This could indeed be very > costly. I can now confirm that the Reflection package, in our case, indeed causes considerable overhead compared to hardcoded constants. The test consisted of 1_000_000 calls to procedure Q in either package P1 or P2: package body P1 is procedure Q is package Reflect is new PragmARC.Reflection; begin Dummy := Dummy + 1; end; end P1; package body P2 is procedure Q is Subprogram_Name : constant String := "Q"; begin Dummy := Dummy + 1; end; end P2; (I'm aware that Reflect.Unit_Name is longer ("P1.Q") than Subprogram_NAme ("Q") but this test is relevant in our case.) I tested on a Sun (Solaris) machine using the GNAT compiler and on a PowerPC (Integrity) using GreenHill's Ada compiler. There was really no need for an accurate time measurement since the difference was large on both platforms. The constant test finished immediately and the Reflection test took several seconds. Optimization flags (GNAT only) didn't do much difference. So although PragmARC.Reflection offers very nice features we cannot use it in our particular system. Thanks for your help! /PerL