Help optimizing code?

user1234 user1234 at 12.nl
Mon Jan 1 15:29:28 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. The code is here: 
> https://github.com/IndigoLily/D-mandelbrot/blob/master/mandelbrot.d
>
> Right now it runs slower than my JavaScript Mandelbrot renderer 
> on the same quality settings, which is clearly ridiculous, but 
> I don't know what to do to fix it. Sorry for the lack of 
> comments, but I can never tell what will and won't be obvious 
> to other people.

- The first thing is to compile with the best options:

     dmd mandelbrot.d -O -release -inline -boundscheck=off

- You append a lot, which can cause reallocs for imageData; Try

    import std.array;
    Appender!(ubyte[]) imageData;

    The code will not have to be changed for "~=" since Appender 
overloads this operator.

- I'd use "double" instead of "real".


More information about the Digitalmars-d-learn mailing list