Superbasic efficiency question
aaronfude_at_gmail.com
Date: 01/24/05
- Next message: Gianni Mariani: "Re: What makes a good C/C++ programmer?"
- Previous message: Gianni Mariani: "Re: What makes a good C/C++ programmer?"
- Next in thread: Joseph Turian: "Re: Superbasic efficiency question"
- Reply: Joseph Turian: "Re: Superbasic efficiency question"
- Reply: Gianni Mariani: "Re: Superbasic efficiency question"
- Reply: Sethalicious: "Re: Superbasic efficiency question"
- Reply: davidrubin_at_warpmail.net: "Re: Superbasic efficiency question"
- Reply: David White: "Re: Superbasic efficiency question"
- Reply: Joseph Turian: "Re: Superbasic efficiency question"
- Reply: davidrubin_at_warpmail.net: "Re: Superbasic efficiency question"
- Reply: davidrubin_at_warpmail.net: "Re: Superbasic efficiency question"
- Reply: davidrubin_at_warpmail.net: "Re: Superbasic efficiency question"
- Reply: davidrubin_at_warpmail.net: "Re: Superbasic efficiency question"
- Reply: Sethalicious: "Re: Superbasic efficiency question"
- Reply: Jonathan Turkanis: "Re: Superbasic efficiency question"
- Reply: Sethalicious: "Re: Superbasic efficiency question"
- Reply: E. Robert Tisdale: "Re: Superbasic efficiency question"
- Reply: Sethalicious: "Re: Superbasic efficiency question"
- Reply: matthias_k: "Re: Superbasic efficiency question"
- Reply: Peter Koch Larsen: "Re: Superbasic efficiency question"
- Reply: chris: "Re: Superbasic efficiency question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 23 Jan 2005 21:06:09 -0800
I'm working on a scientific computing application. I need a class
called Element which is no more than a collection of integers, or
"nodes" and has only on method int getNode(int i).
I would like to implement in the most efficient was possible. So I
summoned up my programming intellect and asked myself: Do I want to
have members such as int a, b, c, d, e or a single member such as int
a[5]. So I wrote the following snippet and compiled it with a -O3 flag:
int main(char *argv[], int argc) {
/*
int a, b, c, d, e;
for (int i = 0; i < 1000000000; i++) {
a = 1;
b = 2;
c = 3;
d = 4;
e = 5;
}
*/
int a[5];
for (int i = 0; i < 1000000000; i++) {
a[0] = 1;
a[1] = 2;
a[2] = 3;
a[3] = 4;
a[4] = 5;
}
return 0;
}
The first (commented out) version ran twice as fast. (For doubles
instead of ints, it was a factor of 4). So the simpleton part of me
thinks that that answers my question. The remaining part tells me that
it is never that simple. Finally, the cynical part of me thinks that it
all doesn't matter and other parts of the program are bound to be far
more time consuming.
Please help me resolve my internal struggle.
Many thanks in advance!
Aaron Fude
- Next message: Gianni Mariani: "Re: What makes a good C/C++ programmer?"
- Previous message: Gianni Mariani: "Re: What makes a good C/C++ programmer?"
- Next in thread: Joseph Turian: "Re: Superbasic efficiency question"
- Reply: Joseph Turian: "Re: Superbasic efficiency question"
- Reply: Gianni Mariani: "Re: Superbasic efficiency question"
- Reply: Sethalicious: "Re: Superbasic efficiency question"
- Reply: davidrubin_at_warpmail.net: "Re: Superbasic efficiency question"
- Reply: David White: "Re: Superbasic efficiency question"
- Reply: Joseph Turian: "Re: Superbasic efficiency question"
- Reply: davidrubin_at_warpmail.net: "Re: Superbasic efficiency question"
- Reply: davidrubin_at_warpmail.net: "Re: Superbasic efficiency question"
- Reply: davidrubin_at_warpmail.net: "Re: Superbasic efficiency question"
- Reply: davidrubin_at_warpmail.net: "Re: Superbasic efficiency question"
- Reply: Sethalicious: "Re: Superbasic efficiency question"
- Reply: Jonathan Turkanis: "Re: Superbasic efficiency question"
- Reply: Sethalicious: "Re: Superbasic efficiency question"
- Reply: E. Robert Tisdale: "Re: Superbasic efficiency question"
- Reply: Sethalicious: "Re: Superbasic efficiency question"
- Reply: matthias_k: "Re: Superbasic efficiency question"
- Reply: Peter Koch Larsen: "Re: Superbasic efficiency question"
- Reply: chris: "Re: Superbasic efficiency question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|