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

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


This revision was automatically updated to reflect the committed changes.
Closed by commit rGdb8716a2ec0b: [libc] Show average runtime for math single-input-single-output performance… (authored by lntue).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D116112/new/

https://reviews.llvm.org/D116112

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


Index: libc/test/src/math/differential_testing/SingleInputSingleOutputDiff.h
===================================================================
--- libc/test/src/math/differential_testing/SingleInputSingleOutputDiff.h
+++ libc/test/src/math/differential_testing/SingleInputSingleOutputDiff.h
@@ -46,28 +46,56 @@
     log << "Total number of differing results: " << diffCount << '\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);
   }
 };
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D116112.395728.patch
Type: text/x-patch
Size: 2865 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20211221/2dba0b61/attachment.bin>


More information about the libc-commits mailing list