[libc-commits] [libc] db8716a - [libc] Show average runtime for math single-input-single-output performance tests.

Tue Ly via libc-commits libc-commits at lists.llvm.org
Tue Dec 21 11:22:40 PST 2021


Author: Tue Ly
Date: 2021-12-21T14:22:20-05:00
New Revision: db8716a2ec0b137191adcdcb622c9badbbcbede8

URL: https://github.com/llvm/llvm-project/commit/db8716a2ec0b137191adcdcb622c9badbbcbede8
DIFF: https://github.com/llvm/llvm-project/commit/db8716a2ec0b137191adcdcb622c9badbbcbede8.diff

LOG: [libc] Show average runtime for math single-input-single-output performance tests.

Run performance tests in denormal and normal ranges separately and show more detailed results.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D116112

Added: 
    

Modified: 
    libc/test/src/math/differential_testing/SingleInputSingleOutputDiff.h

Removed: 
    


################################################################################
diff  --git a/libc/test/src/math/
diff erential_testing/SingleInputSingleOutputDiff.h b/libc/test/src/math/
diff erential_testing/SingleInputSingleOutputDiff.h
index 9a516f9069ce6..7cc7059db03a7 100644
--- a/libc/test/src/math/
diff erential_testing/SingleInputSingleOutputDiff.h
+++ b/libc/test/src/math/
diff erential_testing/SingleInputSingleOutputDiff.h
@@ -46,28 +46,56 @@ template <typename T> class SingleInputSingleOutputDiff {
     log << "Total number of 
diff ering results: " << 
diff Count << '\n';
   }
 
-  static void runPerf(Func myFunc, Func otherFunc, const char *logFile) {
-    auto runner = [](Func func) {
+  static void runPerfInRange(Func myFunc, Func otherFunc, UIntType startingBit,
+                             UIntType endingBit,
+                             testutils::OutputFileStream &log) {
+    auto runner = [=](Func func) {
       volatile T result;
-      for (UIntType bits = 0;; ++bits) {
+      for (UIntType bits = startingBit;; ++bits) {
         T x = T(FPBits(bits));
         result = func(x);
-        if (bits == UIntMax)
+        if (bits == endingBit)
           break;
       }
     };
 
-    testutils::OutputFileStream log(logFile);
     Timer timer;
     timer.start();
     runner(myFunc);
     timer.stop();
-    log << "   Run time of my function: " << timer.nanoseconds() << " ns \n";
+
+    UIntType numberOfRuns = endingBit - startingBit + 1;
+    double myAverage = static_cast<double>(timer.nanoseconds()) / numberOfRuns;
+    log << "-- My function --\n";
+    log << "     Total time      : " << timer.nanoseconds() << " ns \n";
+    log << "     Average runtime : " << myAverage << " ns/op \n";
+    log << "     Ops per second  : "
+        << static_cast<uint64_t>(1'000'000'000.0 / myAverage) << " op/s \n";
 
     timer.start();
     runner(otherFunc);
     timer.stop();
-    log << "Run time of other function: " << timer.nanoseconds() << " ns \n";
+
+    double otherAverage =
+        static_cast<double>(timer.nanoseconds()) / numberOfRuns;
+    log << "-- Other function --\n";
+    log << "     Total time      : " << timer.nanoseconds() << " ns \n";
+    log << "     Average runtime : " << otherAverage << " ns/op \n";
+    log << "     Ops per second  : "
+        << static_cast<uint64_t>(1'000'000'000.0 / otherAverage) << " op/s \n";
+
+    log << "-- Average runtime ratio --\n";
+    log << "     Mine / Other's  : " << myAverage / otherAverage << " \n";
+  }
+
+  static void runPerf(Func myFunc, Func otherFunc, const char *logFile) {
+    testutils::OutputFileStream log(logFile);
+    log << " Performance tests with inputs in denormal range:\n";
+    runPerfInRange(myFunc, otherFunc, /* startingBit= */ UIntType(0),
+                   /* endingBit= */ FPBits::MAX_SUBNORMAL, log);
+    log << "\n Performance tests with inputs in normal range:\n";
+    runPerfInRange(myFunc, otherFunc, /* startingBit= */ FPBits::MIN_NORMAL,
+                   /* endingBit= */ FPBits::MAX_NORMAL, log);
   }
 };
 


        


More information about the libc-commits mailing list