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=-0.3 required=5.0 tests=BAYES_00,HK_RANDOM_FROM, INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,a1a88c4d509f6381 X-Google-Attributes: gid103376,public From: czgrr Subject: Re: scope and/or parameters (beginner) Date: 1999/04/14 Message-ID: <7f1jce$nt4$1@nnrp1.dejanews.com>#1/1 X-Deja-AN: 466205004 References: <37064309.889106243@news.dsuper.net> <37084459.8616007@rocketmail.com> <370b0c99.1137352783@news.dsuper.net> <7ei04q$o$1@nnrp1.dejanews.com> <7et4vr$sdj$1@nnrp1.dejanews.com> <7euskv$d91$1@nnrp1.dejanews.com> <7evbei$opm$1@nnrp1.dejanews.com> X-Http-Proxy: 1.0 x11.dejanews.com:80 (Squid/1.1.22) for client 193.192.234.4 Organization: Deja News - The Leader in Internet Discussion X-Article-Creation-Date: Wed Apr 14 08:24:52 1999 GMT Newsgroups: comp.lang.ada X-Http-User-Agent: Mozilla/4.0 (compatible; MSIE 4.01; Windows NT) Date: 1999-04-14T00:00:00+00:00 List-Id: In article <7evbei$opm$1@nnrp1.dejanews.com>, Robert Dewar wrote: > In article , czgrr wrote: > > So there is a definite difference between the time taken > > to call a routine with and without local variables, > > albeit very small. > > This is plain wrong on many machines. There is no > difference. Furthermore, just because you don't WRITE > any local variables does not mean there are none in the > generated code. [snip] > > So making as much as you can be > > global will improve overall run-time performance > > This is in general quite wrong. Access to local variables > on the stack is generally much more efficient than access > to global variables on modern architectures. > [taken from the end of the post] > Whether something needs to be global or local (in lifetime > or scope) is a logic issue in a program, and not an > efficiency issue that a programmer should worry about. > At the end of this post I have included some code. The output I get is also listed, and you can clearly see a difference between the two sets of procedure calls, with the only code difference being a variable declared locally or globally. I admit the local version is not of much use! Now the difference may be due to something to do with the machine, the memory, the compiler, bind options, etc, but the point I was making is that there *can* be a difference. Yes, in an ideal world the programmer shouldn't have to worry about machine implementations, but this is not an ideal world and if the application being developed is real-time critical, the code given below could make the difference between passing acceptance tests and failing. I said this in my original post, and I say it again, I am not saying that every variable, procedure, etc, should be made global just because it (may be) quicker. Definitely not. Logic issues should determine whether declarations are made local or global, but there are occasional circumstances where practicalities must override the ideal logic. The code below is one of them. [snip] > Indeed since you cannot use "new" with procedures except > in a generic context it is not clear what you are talking > about at all. I was talking about generics, sorry, I jumped contexts there without explaining. I tried what I was talking about on my compiler and, as you say, it made no difference. However, several years ago when I was developing a disk access package with lots of "NEW TEXT_IO.FLOAT_IO" kind of declarations, it definitely made a difference putting them all together at the top of the package rather than individually within each procedure where needed. Again, it may have been the compiler, whatever. But it did matter, and I don't believe that programmers should be unaware of these possibilities. ********** Now, the code I was talking about... PACKAGE temp IS max : INTEGER := 1e5 ; PROCEDURE global ( index : IN INTEGER ) ; PROCEDURE local ( index : IN INTEGER ) ; END temp ; ----- PACKAGE BODY temp IS big_array_global : ARRAY ( 1 .. max ) OF INTEGER ; PROCEDURE global ( index : IN INTEGER ) IS BEGIN big_array_global ( index ) := 0 ; END global ; PROCEDURE local ( index : IN INTEGER ) IS big_array_local : ARRAY ( 1 .. max ) OF INTEGER ; BEGIN big_array_local ( index ) := 0 ; END local ; END temp ; ----- WITH CALENDAR ; WITH TEXT_IO ; WITH temp ; PROCEDURE main IS PACKAGE float_io IS NEW TEXT_IO.FLOAT_IO ( FLOAT ) ; BEGIN float_io.PUT ( FLOAT ( CALENDAR.SECONDS ( CALENDAR.CLOCK ) ) ) ; TEXT_IO.PUT_LINE ( " Calling global..." ) ; FOR i IN 1 .. temp.max LOOP temp.global ( i ) ; END LOOP ; float_io.PUT ( FLOAT ( CALENDAR.SECONDS ( CALENDAR.CLOCK ) ) ) ; TEXT_IO.PUT_LINE ( " Calling local..." ) ; FOR i IN 1 .. temp.max LOOP temp.local ( i ) ; END LOOP ; float_io.PUT ( FLOAT ( CALENDAR.SECONDS ( CALENDAR.CLOCK ) ) ) ; TEXT_IO.PUT_LINE ( " Finished." ) ; DELAY ( 100.0 ) ; END main ; ********** I use ObjectAda Professional Edition version 7.1.1.543, on Windows NT 4.0 with 128MB memory. Output was... 3.67944E+04 Calling global... 3.67945E+04 Calling local... 3.68065E+04 Finished. That is, 0.1 second (to nearest 0.1 second!) to do the global verison, 12.0 seconds to do the local version. czgrr -- My opinions, suggestions, etc, are not necessarily those of my employer. They might not even be right. Use at your own risk. -----------== Posted via Deja News, The Discussion Network ==---------- http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own