<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On 13 December 2013 22:41, logicchains <span dir="ltr"><<a href="mailto:jonathan.t.barnard@gmail.com" target="_blank">jonathan.t.barnard@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">I've posted a couple of benchmarks involving D previously and received complaints that the D implementation was ugly and un-idiomatic, so I thought I'd seek code review before posting the next one. The code is at <a href="https://github.com/logicchains/ParticleBench/blob/master/D.d" target="_blank">https://github.com/<u></u>logicchains/ParticleBench/<u></u>blob/master/D.d</a>; it's an OpenGL particle animation, and my D code is essentially just a direct port of the C implementation. Note however that, as the animation is gpu-bound, there's not much scope for optimisation of the code (in hindsight, it was a pretty poor topic for a benchmark, but hindsight always sees farthest and whatnot).<br>

</blockquote></div><br></div><div class="gmail_extra">Is it idiomatic to use egyptian braces in D? I've never seen D code written this way... looks like Java.</div><div class="gmail_extra"><br></div><div class="gmail_extra">
You have a lot of globals, and they're all TLS. That seems inefficient, and potentially incorrect if there were threads.</div><div class="gmail_extra"><br></div><div class="gmail_extra">Why do you build the vertex array from literal data at runtime? Why not just initialise the array?</div>
<div class="gmail_extra">It's a static array, so it's not allocated at runtime, so it shouldn't be any different. You'd probably save a lot of LOC to initialise the array, perhaps better for clarity. It should probably also be immutable?</div>
<div class="gmail_extra"><br></div><div class="gmail_extra">Those integer for loops might be nicer as: foreach(i; 0 .. n)</div><div class="gmail_extra"><br></div><div class="gmail_extra">I'm not personally in the camp that agrees:</div>
<div class="gmail_extra">  double</div><div class="gmail_extra">    x = 0,</div><div class="gmail_extra">    y = 10,</div><div class="gmail_extra">    z = 15;</div><div class="gmail_extra">is a good thing... but each to their own :)</div>
<div class="gmail_extra"><br></div><div class="gmail_extra">Why are you using 'double' in realtime software? That's weird isn't it? Granted, it will make no difference on x86, but I'd never personally do this for portability reasons.</div>
<div class="gmail_extra"><br></div><div class="gmail_extra">But generally looks fine. Any opengl code is naturally going to look C-ish by nature. And yes, as you said, it's not really a very good benchmark, since you're really benchmarking the GPU (and the legacy fallback non-shader pipeline at that) ;) .. The mainloop barely does anything, and has very few iterations.</div>
<div class="gmail_extra"><br></div><div class="gmail_extra">Nitpick: I think properness would have you update the velocity before the position, or you'll always run 1 frame behind.</div><div class="gmail_extra">There are a lot more really minor performance hazards that I'd never let slip if they were invoked in hot loops, but they won't make any difference here.</div>
</div>