# HG changeset patch # User Chris Cannam # Date 1399376639 -3600 # Node ID 6075e92d63abfd4b472999b65399c875a4e279f2 # Parent 64b08cc12da07834d8c50982cb4ce055347c43ee Reorder internal loops diff -r 64b08cc12da0 -r 6075e92d63ab src/EM.cpp --- a/src/EM.cpp Tue May 06 12:39:19 2014 +0100 +++ b/src/EM.cpp Tue May 06 12:43:59 2014 +0100 @@ -182,20 +182,22 @@ const float *w = templateFor(i, n, f); const double factor = pitch * source * shift; - for (int j = 0; j < m_binCount; ++j) { + if (n >= m_lowestPitch && n <= m_highestPitch) { - const double contribution = w[j] * m_q[j] * factor; - - if (n >= m_lowestPitch && n <= m_highestPitch) { - newPitches[n] += contribution; + for (int j = 0; j < m_binCount; ++j) { + newPitches[n] += w[j] * m_q[j] * factor; } - newShifts[f][n] += contribution; - if (inRange(i, n)) { - newSources[i][n] += contribution; + for (int j = 0; j < m_binCount; ++j) { + newSources[i][n] += w[j] * m_q[j] * factor; + } } } + + for (int j = 0; j < m_binCount; ++j) { + newShifts[f][n] += w[j] * m_q[j] * factor; + } } } } diff -r 64b08cc12da0 -r 6075e92d63ab testdata/timing/results.txt --- a/testdata/timing/results.txt Tue May 06 12:39:19 2014 +0100 +++ b/testdata/timing/results.txt Tue May 06 12:43:59 2014 +0100 @@ -102,3 +102,10 @@ conclusion: compiler already knows this stuff +commit:64b08cc12da0, as commit:ce64d11ef336 but with loops merged so +as theoretically to reduce intermediate calculations + +real 3m46.969s +user 3m46.850s +sys 0m0.220s +