lmi-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi-commits] [lmi] master d97c255 3/4: Make 'vector_test' timings more


From: Greg Chicares
Subject: [lmi-commits] [lmi] master d97c255 3/4: Make 'vector_test' timings more meaningful
Date: Thu, 11 May 2017 16:53:07 -0400 (EDT)

branch: master
commit d97c2559f10d524d6a5d42aa850ff3993da2b093
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>

    Make 'vector_test' timings more meaningful
    
    This change resembles the last and especially the second-to-last
    commit, q.v.
---
 vector_test.cpp | 31 +++++++++++++++++++++++--------
 1 file changed, 23 insertions(+), 8 deletions(-)

diff --git a/vector_test.cpp b/vector_test.cpp
index b2a7a17..df3507d 100644
--- a/vector_test.cpp
+++ b/vector_test.cpp
@@ -269,13 +269,19 @@ void demo1()
 
 namespace
 {
-    // Global variables for timing tests. It would be in better taste
-    // to pass them as arguments, using std::bind. However, that
-    // would rule out using some compilers (e.g., borland), and it's
-    // best to test this with as many different toolsets as possible.
+    // Global variables for timing tests. They could alternatively be
+    // passed as arguments, e.g., by using std::bind, but that would
+    // increase complexity in return for no real benefit.
 
     int g_array_length = 1;
 
+    // Number of iterations for 'mete*' functions. This value is a
+    // compromise: higher values make this unit test take too long,
+    // while lower values may yield measurements that are less than
+    // a one-microsecond timer tick.
+
+    int const n_iter = 100;
+
     simple_array0 g_u(g_array_length);
     simple_array0 g_v(g_array_length);
     simple_array0 g_w(g_array_length);
@@ -287,20 +293,29 @@ namespace
 
 void mete_c()
 {
-    for(int i = 0; i < g_array_length; ++i)
+    for(int i = 0; i < n_iter; ++i)
         {
-        g_w[i] = g_u[i] + g_v[i];
+        for(int j = 0; j < g_array_length; ++j)
+            {
+            g_w[j] = g_u[j] + g_v[j];
+            }
         }
 }
 
 void mete_et()
 {
-    g_w = g_u + g_v;
+    for(int i = 0; i < n_iter; ++i)
+        {
+        g_w = g_u + g_v;
+        }
 }
 
 void mete_va()
 {
-    g_va_w = g_va_u + g_va_v;
+    for(int i = 0; i < n_iter; ++i)
+        {
+        g_va_w = g_va_u + g_va_v;
+        }
 }
 
 void time_one_array_length(int length)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]