OSDN Git Service

BinderAddInts benchmark change to spin delay
authorLouis Huemiller <lhuemill@google.com>
Mon, 10 Jan 2011 01:54:25 +0000 (17:54 -0800)
committerLouis Huemiller <lhuemill@google.com>
Mon, 10 Jan 2011 01:54:25 +0000 (17:54 -0800)
Change-Id: Ib98190b3c6f6ac934c5ca74ec221c5391152f189

tests/binder/benchmarks/binderAddInts.cpp
tests/include/testUtil.h
tests/lib/testUtil/testUtil.c

index d452a89..21b76bf 100644 (file)
@@ -294,7 +294,7 @@ static void client(void)
             cerr << "expected: " << expected << endl;
         }
 
-        if (options.iterDelay > 0.0) { testDelay(options.iterDelay); }
+        if (options.iterDelay > 0.0) { testDelaySpin(options.iterDelay); }
     }
 
     // Display the results
index 7e04742..3b75914 100644 (file)
@@ -35,6 +35,7 @@ struct timeval tvDelta(const struct timeval *first,
     const struct timeval *second);
 
 void testDelay(float amt);
+void testDelaySpin(float amt);
 
 // Pseudo Random Utilities
 int testRandBool(void);
index abe57d1..d63fbba 100644 (file)
@@ -282,6 +282,27 @@ void testDelay(float amt)
     } while (true);
 }
 
+// Delay spins for the number of seconds specified by amt or a greater
+// amount.  The amt variable is of type float and thus non-integer amounts
+// of time can be specified.  Differs from testDelay() in that
+// testDelaySpin() performs a spin loop, instead of using nanosleep().
+void testDelaySpin(float amt)
+{
+    struct timespec   start, current, delta;
+
+    // Get the time at which we started
+    clock_gettime(CLOCK_MONOTONIC, &start);
+
+    do {
+        // Get current time
+        clock_gettime(CLOCK_MONOTONIC, &current);
+
+        // How much time is left
+        delta = tsDelta(&start, &current);
+        if (ts2double(&delta) > amt) { break; }
+    } while (true);
+}
+
 /*
  * Hex Dump
  *