On Monday, 1 January 2018 at 15:23:19 UTC, Adam D. Ruppe wrote:
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.

Yes I've also adviced double. Double is better if the target arch is X86_64 since part of the operations will be made with SSE. With "real" the OP was **sure** to get 100% of the maths done in the FPU (although for all the trigo stuff there's no choice)


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.


Reply via email to