Question about performance using compound list for initialization?
Markus Lidel
Markus.Lidel@shadowconnect.com
Fri May 13 01:06:00 GMT 2005
Hi...
I tried to find out which is the best way to get variables initialized.
So i wrote the following little functions:
int test1(int i) {
int f[1000];
f[0] = 0;
f[1] = 1;
[...]
f[998] = 998;
f[999] = 999;
return f[i];
};
int test2(int i) {
int f[1000] = {
0, 1, [...], 998, 999
};
return f[i];
}
Now i called test1() n-times and test2() n-times. The size when using
test1() was twice as test2(). But when comparing the time to my
astonishment test2() took twice as long as test1(). This is always the
case, independent of optimation. I've also tried it with 3.3.5 and 3.4.3
without any difference. Although it is not the usual case to initialize
1000 elements, i really wonder why test2() is slower then test1()?
Thank you very much,
Best regards,
Markus Lidel
------------------------------------------
Markus Lidel (Senior IT Consultant)
Shadow Connect GmbH
Carl-Reisch-Weg 12
D-86381 Krumbach
Germany
Phone: +49 82 82/99 51-0
Fax: +49 82 82/99 51-11
E-Mail: Markus.Lidel@shadowconnect.com
URL: http://www.shadowconnect.com
More information about the Gcc-help
mailing list