Help optimizing code?

Adam D. Ruppe destructionator at gmail.com
Mon Jan 1 15:23:19 UTC 2018


On Monday, 1 January 2018 at 15:09:53 UTC, Lily wrote:
> I started learning D a few days ago, coming from some very 
> basic C++ knowledge, and I'd like some help getting a program 
> to run faster.

So a few easy things you can do:

1) use `float` instead of `real`. real sucks, it is really slow 
and weird. Making that one switch doubled the speed on my 
computer.

2) preallocate the imageData. before the loop, 
`imageData.reserve(width*height*3)`. Small savings on my computer 
but an easy one.

3) make sure you use the compiler optimization options like `-O` 
and `-inline` on dmd (or use the gdc and ldc compilers both of 
which generally optimize better than dmd out of the box).


And if that isn't enough we can look into smaller things, but 
these overall brought the time down to about 1/3 what it started 
on my box.


More information about the Digitalmars-d-learn mailing list