[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 07:49:51 PST 2021
lntue created this revision.
lntue added reviewers: sivachandra, michaelrj, zimmermann6, cqlauter.
Herald added subscribers: ecnelises, tschuett.
Herald added a project: libc-project.
lntue requested review of this revision.
Run performance tests in denormal and normal ranges separately and show more detailed results.
Repository:
rG LLVM Github Monorepo
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.395680.patch
Type: text/x-patch
Size: 2865 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20211221/8eff0e75/attachment-0001.bin>
More information about the libc-commits
mailing list