digitalmars.D - AAs of struct or array
- bearophile (25/25) May 27 2010 I have noticed a significant speed difference between foo1 and foo2 (D2 ...
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (6/37) May 27 2010 Most of it comes from the use of that temporary. -O doesn't help either.
- bearophile (4/5) May 27 2010 Right. I will probably put this in Bugzilla, even if it's a low priority...
- bearophile (1/1) May 27 2010 http://d.puremagic.com/issues/show_bug.cgi?id=4244
- Pelle (3/28) May 27 2010 On my machine, foo1 takes around 9 times longer.
I have noticed a significant speed difference between foo1 and foo2 (D2 code):
import std.c.stdio: printf;
int foo1(int x, int y) {
static int[int[2]] cache;
int[2] args = [x, y];
cache[args] = x;
return x;
}
int foo2(int x, int y) {
static struct Pair { int x, y; }
static int[Pair] cache;
Pair args = Pair(x, y);
cache[args] = x;
return x;
}
void main() {
enum int N = 600;
int tot;
foreach (x; 1 .. N)
foreach (y; 1 .. N)
tot += foo2(x, y); // use foo1 or foo2 here
printf("%d\n", tot);
}
Bye,
bearophile
May 27 2010
bearophile wrote:I have noticed a significant speed difference between foo1 and foo2 (D2 code): import std.c.stdio: printf; int foo1(int x, int y) { static int[int[2]] cache; int[2] args = [x, y]; cache[args] = x;Most of it comes from the use of that temporary. -O doesn't help either. This makes foo1 only slightly slower than foo2: // int[2] args = [x, y]; cache[[x, y]] = x;return x; } int foo2(int x, int y) { static struct Pair { int x, y; } static int[Pair] cache; Pair args = Pair(x, y); cache[args] = x; return x; } void main() { enum int N = 600; int tot; foreach (x; 1 .. N) foreach (y; 1 .. N) tot += foo2(x, y); // use foo1 or foo2 here printf("%d\n", tot); } Bye, bearophileAli
May 27 2010
Ali Çehreli:Most of it comes from the use of that temporary. -O doesn't help either.Right. I will probably put this in Bugzilla, even if it's a low priority thing. Bye, bearophile
May 27 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4244
May 27 2010
On 05/27/2010 02:33 PM, bearophile wrote:
I have noticed a significant speed difference between foo1 and foo2 (D2 code):
import std.c.stdio: printf;
int foo1(int x, int y) {
static int[int[2]] cache;
int[2] args = [x, y];
cache[args] = x;
return x;
}
int foo2(int x, int y) {
static struct Pair { int x, y; }
static int[Pair] cache;
Pair args = Pair(x, y);
cache[args] = x;
return x;
}
void main() {
enum int N = 600;
int tot;
foreach (x; 1 .. N)
foreach (y; 1 .. N)
tot += foo2(x, y); // use foo1 or foo2 here
printf("%d\n", tot);
}
Bye,
bearophile
On my machine, foo1 takes around 9 times longer.
Why is this?
May 27 2010









bearophile <bearophileHUGS lycos.com> 