This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
| Other format: | [Raw text] | |
This is somewhat silly code from one of our customers that does an
initialization of a large array like so:
typedef struct sELEM {
const char *N;
unsigned S;
void *A;
} sELEM;
sELEM tab[2500];
int a[2500];
void init_tab(void)
{
tab[0].N = "a[0]";
tab[0].S = sizeof(a[0]);
tab[0].A = &a[0];
tab[1].N = "a[1]";
tab[1].S = sizeof(a[1]);
tab[1].A = &a[1];
...
Now in this case it obviously makes more sense to do something like:
sELEM tab[2500] ={
{"a[0]", sizeof(a[0]), &a[0]},
{"a[1]", sizeof(a[1]), &a[1]},
...
but the interesting thing is the time taken to compile the first case if
optimization is used. A straight compile with no optimization takes a
couple seconds but with -O it takes on the order of 5-10 minutes.
time gcc -c dummy.c -> 2.28s real
time gcc -O -c dummy.c -> 340.31s real
I got the same results with 2.95.3 and 3.2.1 and the resulting object code
is pretty much identical. I expect this is just a matter of "don't do that"
in this case (since you can use the static initializer) but there may be
situations where you can't so I though I'd report it on the off chance that
no one has seen this before.
cheers,
Kris
Attachment:
stuff.tgz
Description: application/compressed
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |