lmi-commits
[Top][All Lists]
Advanced

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

[lmi-commits] [lmi] master dbcfee12 1/2: Test speed of expm1() and log1p


From: Greg Chicares
Subject: [lmi-commits] [lmi] master dbcfee12 1/2: Test speed of expm1() and log1p()
Date: Sun, 22 May 2022 19:40:44 -0400 (EDT)

branch: master
commit dbcfee1227dfdb46ba87da4a8874c47478110668
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>

    Test speed of expm1() and log1p()
    
    Namespace lmi contains code imported from fdlibm.
    
    MinGW-w64 is significantly slower, and less accurate assuming that
    fdlibm returns correctly rounded results in most cases:
    
    x86_64, sse, gcc, msw
      lmi::expm1()     9.707e-04 s mean;        938 us least of 100 runs
      std::expm1()     1.500e-03 s mean;       1440 us least of 100 runs
      lmi::log1p()     9.032e-04 s mean;        881 us least of 100 runs
      std::log1p()     3.502e-03 s mean;       3382 us least of 100 runs
    
    pc-linux-gnu's glibc has an adaptation of fdlibm, which (as previously
    demonstrated) gives the same results in almost all cases tested; but
    glibc is faster:
    
    x86_64, sse, gcc, posix
      lmi::expm1()     8.419e-04 s mean;        819 us least of 100 runs
      std::expm1()     7.920e-04 s mean;        751 us least of 100 runs
      lmi::log1p()     8.969e-04 s mean;        871 us least of 100 runs
      std::log1p()     8.280e-04 s mean;        797 us least of 100 runs
---
 math_functions_test.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)

diff --git a/math_functions_test.cpp b/math_functions_test.cpp
index 8acac065..07f54e0b 100644
--- a/math_functions_test.cpp
+++ b/math_functions_test.cpp
@@ -236,6 +236,48 @@ void mete5()
     stifle_unused_warning(x);
 }
 
+// These 'mete[6789]' functions test the speed of exmp1() and log1p().
+
+void mete6()
+{
+    double volatile x;
+    for(int j = 0; j < 100000; ++j)
+        {
+        x = lmi::expm1(0.0032737397821988637);
+        }
+    stifle_unused_warning(x);
+}
+
+void mete7()
+{
+    double volatile x;
+    for(int j = 0; j < 100000; ++j)
+        {
+        x = std::expm1(0.0032737397821988637);
+        }
+    stifle_unused_warning(x);
+}
+
+void mete8()
+{
+    double volatile x;
+    for(int j = 0; j < 100000; ++j)
+        {
+        x = lmi::log1p(0.04);
+        }
+    stifle_unused_warning(x);
+}
+
+void mete9()
+{
+    double volatile x;
+    for(int j = 0; j < 100000; ++j)
+        {
+        x = std::log1p(0.04);
+        }
+    stifle_unused_warning(x);
+}
+
 void test_assign_midpoint()
 {
     constexpr double smallnum = std::numeric_limits<double>::denorm_min();
@@ -688,6 +730,10 @@ void assay_speed()
     std::cout << "  long double i365 " << TimeAnAliquot(mete3) << '\n';
     std::cout << "  10^-9 nonstd     " << TimeAnAliquot(mete4) << '\n';
     std::cout << "  10^-9 std        " << TimeAnAliquot(mete5) << '\n';
+    std::cout << "  lmi::expm1()     " << TimeAnAliquot(mete6) << '\n';
+    std::cout << "  std::expm1()     " << TimeAnAliquot(mete7) << '\n';
+    std::cout << "  lmi::log1p()     " << TimeAnAliquot(mete8) << '\n';
+    std::cout << "  std::log1p()     " << TimeAnAliquot(mete9) << '\n';
     std::cout << std::flush;
 }
 



reply via email to

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