Struct method access speed

Jarrod qwerty at ytre.wq
Wed Dec 26 18:21:58 PST 2007


On Thu, 27 Dec 2007 02:02:09 +0000, Jarrod wrote:

>> The one that surprises me is gdc. For DMD, you actually fill the vector
>> twice in the first loop (once with zeroes, then a second time with
>> values) and it runs about twice as long as the second loop which is
>> normal. However, for gdc, I can't explain the large time for the first
>> loop...
>> 
>> 		Jerome
> 
> I agreed with you so I tested it out. I removed the for loop in create:
> void create() {
>   ap = cast(T*)malloc(N * T.sizeof);
> }
> 
> Results:
> timbus at TiMBoX:~/Desktop$ dmd -O -release -inline what.d gcc what.o -o
> what -m32 -lphobos -lpthread -lm timbus at TiMBoX:~/Desktop$ ./what
> 0.37
> 0.19
> 
> Seems opIndexAssign needs a bit of fine tuning.

I also added the following method to the struct:

  void assign(T x, uint i){
    ap[i] = x;
  }

Then instead of using v1[i] = j; I used v1.assign(j, i);
It worked just as fast as the v2 way.

So it's not an issue with member access. It's an issue with overloading 
the array operator.



More information about the Digitalmars-d mailing list