stack access speed
15 Nov 2000 00:03:49 -0500

          From comp.compilers

Related articles
stack access speed (2000-11-15)
Re: stack access speed (david lindauer) (2000-11-16)
Re: stack access speed (2000-11-17)
| List of all articles for this month |

Newsgroups: comp.compilers
Date: 15 Nov 2000 00:03:49 -0500
Organization: Compilers Central
Keywords: C, GCC, performance, question, comment
Posted-Date: 15 Nov 2000 00:03:48 EST

Hi all:

My name is Alan and I have a question that I need some help from all
great minds in this forum.

The question are as follow:


Platform 1 = Pentium 600 ,Win NT 4.0 + SP4 , Visual C++ 6.0
Platform 2 = Pentium 600, Suse Linux 6.4 , GCC compiler 2.95.2 with
optimize flag '-O2' set.

I have programmed the following code for a small test and run it on two
different platform as stated above.I have run the test for 100,000
times and time it when it start and finish excuting the program.


unsigned long bigArray1[500];
unsigned long bigArray2[500];
unsigned long bigArray3[500];
unsigned long bigArray4[500];
unsigned long bigArray5[500];
unsigned long bigArray6[500];
unsigned long bigArray7[500];
unsigned long bigArray8[500];
unsigned long i;

for (i=0;i<500;i++) {
bigArray2[i] = bigArray1[i] + i;
bigArray3[i] = bigArray2[i] + bigArray1[i];
bigArray4[i] = bigArray3[i] + bigArray2[i];
bigArray5[i] = bigArray4[i] + bigArray3[i];
bigArray6[i] = bigArray5[i] + bigArray4[i];
bigArray7[i] = bigArray6[i] + bigArray5[i];
bigArray8[i] = bigArray7[i] + bigArray6[i];

The results is as follow:
MS Visual C++ = ~900ms
Linux with GCC = ~2000ms

We then change the declaration of these arrays to "static" and rerun
the test, the result are as follow:

MS Visual C++ = ~900ms
Linux with GCC = ~950ms

We have isolated the problem to be "access speed to locally defined
automatic arrays" i.e. stack access speed. Our arrays are typically 1
KB in size and we use lots of them in our functions. As shown above, we
ran some timing tests for simple manipulation of arrays cells and found
that arrays defined as "automatic" ran significantly slower than arrays
defined as "static". This has caused our program to crawl in certain
instances when arrays are constantly being pushed and popped from the
stack. Is there a way to configure Linux to be more efficient in this
regard, or possibly we have missed something in GCC?

Any help would be much appreciated here. Thank you for your time.

[Well, if you use -O6 the code is somewhat better. -John]

Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.