changeset 86:6075e92d63ab timing

Reorder internal loops
author Chris Cannam
date Tue, 06 May 2014 12:43:59 +0100
parents 64b08cc12da0
children a44c52983ec2
files src/EM.cpp testdata/timing/results.txt
diffstat 2 files changed, 17 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- 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;
+                }
             }
         }
     }
--- 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
+