From a C++/JS benchmark

Iain Buclaw ibuclaw at ubuntu.com
Sat Aug 6 16:04:11 PDT 2011


== Quote from bearophile (bearophileHUGS at lycos.com)'s article
> Iain Buclaw:
> > 1) using pointers over dynamic arrays. (5% speedup)
> > 2) removing the calls to CalVector4's constructor (5.7% speedup)
> With DMD I have seen 180k -> 190k vertices/sec replacing this:
> struct CalVector4 {
>     float X, Y, Z, W;
>     this(float x, float y, float z, float w = 0.0f) {
>         X = x;
>         Y = y;
>         Z = z;
>         W = w;
>     }
> }
> With:
> struct CalVector4 {
>     float X, Y, Z, W=0.0f;
> }
> I'd like the D compiler to optimize better there.
> > http://ideone.com/4PP2D
> This line of code is not good:
> auto vertices = cast(Vertex *) new Vertex[N];
> This is much better, it's less bug-prone, simpler and shorter:
> auto vertices = (new Vertex[N]).ptr;
> But in practice in this program it is enough to allocate dynamic arrays
normally, and then perform the call like this (with DMD it gives the same
performance):
> calculateVerticesAndNormals(boneTransforms.ptr, N, vertices.ptr, influences.ptr,
output.ptr);

I was playing about with heap vs stack. Must've forgot to remove that, sorry. :)

Anyways, I've tweaked the GDC codegen, and program speed meets that of C++ now (on
my system).

Implementation: http://ideone.com/0j0L1

Command-line:
gdc -O3 -mfpmath=sse -ffast-math -march=native -frelease
g++ bench.cc -O3 -mfpmath=sse -ffast-math -march=native

Best times:
G++-32bit:  11400000 vps
GDC-32bit:  11350000 vps


Regards
Iain


More information about the Digitalmars-d mailing list