0

I tried coding something in c#, which generates a mandelbrot set image (with smooth coloring), and it worked but produced very slow, probably because c# isn't the best language for it. What woould be the best language to generate lots of images in the shortest time?

Potheker
  • 93
  • 8
  • Maybe it's slow because of your algorithm? Maybe that's the question you should be asking, instead of this one which is primarily opinion-based. – Some programmer dude Aug 30 '17 at 11:05
  • And please take some time to read [the help pages](http://stackoverflow.com/help), especially the sections named ["What topics can I ask about here?"](http://stackoverflow.com/help/on-topic) and ["What types of questions should I avoid asking?"](http://stackoverflow.com/help/dont-ask). Also please [take the tour](http://stackoverflow.com/tour) and [read about how to ask good questions](http://stackoverflow.com/help/how-to-ask). Lastly please learn how to create a [Minimal, Complete, and Verifiable Example](http://stackoverflow.com/help/mcve). – Some programmer dude Aug 30 '17 at 11:06
  • 1
    Just to give you some hint, how fast are Mandelbrot algorithms (black&white, 16k x 16k pixels large): https://benchmarksgame.alioth.debian.org/u64q/mandelbrot.html C# is about the 20th, with ~7 seconds. – karatedog Aug 30 '17 at 11:57
  • The crux of the matter is the huge computation required to iterate the MSet. I solved it by 1) Working in C with inline assembler. The received wisdom is to let the compiler do the optimisation for you. But my solution iterates the function entirely within the FPU registers, except the escape test and the iteration count, which means only 1 memory R and 1 R/W per iteration. 2) By not iterating anywhere I don't have to, which means contour stitching and interior fill. Quite tricky to get both parts right. – Weather Vane Sep 02 '17 at 23:07

1 Answers1

1

The programming language does not matter. The fastest is to do the calculation on the GPU using eg CUDA or OpenCL.

Just do a search for Mandelbrot Set Realtime GPU. Some examples that I found:

(Disclaimer, none of them is mine, but I use Renderscript for a similar purpose in Android)

Side note 1: You can also implement a fractal renderer directly in C# and it will be equally fast as any other in C or C#, but you should not create new objects on the heap for each calculation step (or use a library for complex numbers that does exactly this). Either use double-variables or reuse existing objects.

Side note 2: Using arbitrary precision will always be slow.

Searles
  • 1,447
  • 1
  • 11
  • 26
  • GPU is fastest if computation can be made in parallel way. GPU has problem with arbitrary precision – Adam Nov 15 '17 at 18:04