Skip to content

C# mandelbrot line-by-line from Swift program # 7

CONTRIBUTE SOURCE CODE

Provide a helpful Title

C# mandelbrot line-by-line from Swift program # 7 by Arseniy Zlobintsev

Attach your source code file

Mandelbrot.csMandelbrot.csproj

Provide an example build command-line

dotnet publish -o .
curl https://benchmarksgame-team.pages.debian.net/benchmarksgame/download/mandelbrot-output.txt >> expected.bmp
./Mandelbrot >> actual.bmp
cmp --silent expected.bmp actual.bmp || echo "different"

Executes in about 465ms on 6P+2E M1 Pro (which has 128x4 units on large cores) and in about 190ms on 8C Zen 3 (which blasts through the test with low-latency 256x4 units).

Discussion

Yet another Mandelbrot, yes. This time around, however, it avoids using unsafe code while still utilizing portable fixed-width SIMD. I think what makes it interesting is exploring more or less equivalent API between Swift and C#, and how they end up performing under very different compilers while being deconstructed into smaller-sized vectors supported by the underlying hardware (256x2 or even 128x4) which stresses the areas such as register allocation, struct promotion (mem2reg promotion in LLVM terms), and competent SIMD instruction selection.

Implementations of this type are sensitive to width and count of SIMD units on a single CPU core (i.e. massively faster on newer CPUs, Sandy and Ivy Bridges were the Intel's first foray into wider vector units), as well as the core count itself.

There are multiple F# submissions for this suite that are currently broken due to overload resolution conflicts - I plan to submit fixes for them later on.