digitalmars.D - A trouble with constructors
- bearophile (23/23) Nov 22 2010 While optimizing some code I have seen that adding a basic struct constr...
While optimizing some code I have seen that adding a basic struct constructor
produces a large difference in performance, this is a test program:
enum bool use_ctor = true;
struct Foo {
static if (use_ctor) {
double x, y, z;
pure nothrow this(double x_, double y_, double z_) {
this.x = x_;
this.y = y_;
this.z = z_;
}
} else {
double x=0.0, y=0.0, z=0.0;
}
Foo muls(double s) {
return Foo(this.x*s, this.y*s, this.z*s);
}
}
void main() {}
Changing use_ctor from true to false changes a lot the amount of asm code
produced and the performance of a program that uses this structs.
For asm listings and more info click here:
http://d.puremagic.com/issues/show_bug.cgi?id=5254
Bye,
bearophile
Nov 22 2010








bearophile <bearophileHUGS lycos.com>