Old problem with performance

Sean Kelly sean at invisibleduck.org
Sun Feb 8 07:04:06 PST 2009


Frits van Bommel wrote:
> Walter Bright wrote:
>> Weed wrote:
>>> Daniel Keep пишет:
>>>> Weed wrote:
>>>>> [snip]
>>>> If I had to take a guess, I'd say that it's six times slower because
>>>> you're performing 100 million allocations.  You aren't benchmarking
>>>> class/struct overhead, you're benchmarking the overhead of doing 100
>>>> million allocations.
>>>>
>>>> You're comparing apples and heffalumps.
>>>
>>> Yes, but problem is that D does not leave  way to create a class
>>> instance without allocation
>>
>> You can allocate a class on the stack with:
>>
>>    scope c = new C();
> 
> Which helps (a bit) with the two instances allocated in main(), but is 
> rather unhelpful with the 100_000_000 allocated in opAdd() (they're 
> returned)...

It's kind of a lame solution, but if the return value is const then the 
class could just hold a reference to an internal value it changes as needed.


Sean



More information about the Digitalmars-d mailing list