Implementing and optimizing a simple graph metric
Joseph Rushton Wakeling
joseph.wakeling at webdrake.net
Wed Sep 18 10:19:06 PDT 2013
On Wednesday, 18 September 2013 at 15:17:25 UTC, Joseph Rushton
> I think I did give std.array.Array a trial when trying to speed
> up its performance, and I don't remember it making any
> difference (if anything it may have slowed things down). But
> I'll give it a second look and report back.
I tried rewriting the variable declarations:
centrality.length = g.vertexCount;
centrality = to!T(0);
stack.length = g.vertexCount;
sigma.length = g.vertexCount;
delta.length = g.vertexCount;
d.length = g.vertexCount;
auto q = VertexQueue(g.vertexCount);
Appender!(size_t) p = new
It results in a moderate slowdown of the code, at a guess because
it increases the total number of mallocs/deallocs.
I note that there seems to be no way to initialize
std.container.Array as having a certain length ... ?
I tried instead using std.array.uninitializedArray to initialize
the arrays in the betweenness() function -- it was a bit
difficult to judge here: with a relatively small number of calls
to betweenness() it seems to have resulted in a speedup, but with
very many calls, it seems to have been slower.
More information about the Digitalmars-d-announce