ketmar:
Thank you for your analysis and code.
while (x.length) {
foreach (key; x.keys) {
auto pp = key in x;
if (pp is null) continue;
j = key;
p = *pp;
x.remove(j);
This is a little cleaner:
while (x.length) {
foreach (immutable j; x.keys) {
p = x[j];
x.remove(j);
so yes, creating delegates are SLOW. even taking into account
that we creating dynamic arrays with keys in this version, it's
rockin' fast.
This D version is much faster, it runs in about 0.26 seconds
(while the C++ version runs in about 0.21 seconds), this is
acceptable because x.keys allocates a dynamic array of keys in
the middle of the code.
But I think the "j = x.byKey.front; p = x.byValue.front;" code
looks sufficiently idiomatic, and its performance is terrible. It
seems fit for a performance bug report. I have to create a
synthetic benchmark that shows just the problem.
Bye,
bearophile