octave-bug-tracker
[Top][All Lists]
Advanced

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

[Octave-bug-tracker] [bug #50561] 350X slower code for eps() written in


From: Rik
Subject: [Octave-bug-tracker] [bug #50561] 350X slower code for eps() written in C++ rather than an m-file
Date: Thu, 16 Mar 2017 11:22:08 -0400 (EDT)
User-agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:43.0) Gecko/20100101 Firefox/43.0

URL:
  <http://savannah.gnu.org/bugs/?50561>

                 Summary: 350X slower code for eps() written in C++ rather
than an m-file
                 Project: GNU Octave
            Submitted by: rik5
            Submitted on: Thu 16 Mar 2017 08:22:07 AM PDT
                Category: Octave Function
                Severity: 3 - Normal
                Priority: 5 - Normal
              Item Group: Performance
                  Status: None
             Assigned to: None
         Originator Name: 
        Originator Email: 
             Open/Closed: Open
         Discussion Lock: Any
                 Release: dev
        Operating System: Any

    _______________________________________________________

Details:

The eps is written in C++, and thus should be very fast.  However, it is
easily beaten by an m-file implementation which is 350X faster and gets the
same results.

What is going on here?  And does this explain why Octave seems to have been
getting slower over the years?

The C++ code is in libinterp/corefcn/data.cc


          Array<double> x = arg0.array_value ();

          Array<double> epsval (x.dims ());

          for (octave_idx_type i = 0; i < x.numel (); i++)
            {
              double val = ::fabs (x(i));
              if (octave::math::isnan (val) || octave::math::isinf (val))
                epsval(i) = lo_ieee_nan_value ();
              else if (val < std::numeric_limits<double>::min ())
                epsval(i) = pow (2.0, -1074e0);
              else
                {
                  int expon;
                  octave::math::frexp (val, &expon);
                  epsval(i) = std::pow (2.0,
                                        static_cast<double> (expon - 53));
                }

              retval = epsval;
            }


My m-file version


function [retval] = myeps (x)

  retval = abs (x);
  idx1 = isnan (retval) | isinf (retval);
  idx2 = retval < realmin;
  retval(idx1) = NaN;
  retval(idx2) = pow2 (-1074);
  idx3 = ! (idx1 | idx2);
  [~, exponent] = log2 (retval(idx3));
  retval(idx3) = pow2 (exponent - 53); 

endfunction


The results of testing


octave:45> x = randi (1e6, [1e5,1]);
octave:46> tic; y = eps (x); toc
Elapsed time is 3.175 seconds.
octave:47> tic; y2 = myeps (x); toc
Elapsed time is 0.00889206 seconds.
octave:48> 3.175/.00889206
ans =  357.06
octave:49> isequal (y,y2)
ans = 1
octave:50> diary off







    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?50561>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/




reply via email to

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