View mode: basic / threaded / horizontal-split · Log in · Help
November 22, 2010
A trouble with constructors
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:

Top | Discussion index | About this forum | D home