[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Octave-bug-tracker] [bug #51403] isequal is slow
From: |
Mike Miller |
Subject: |
[Octave-bug-tracker] [bug #51403] isequal is slow |
Date: |
Thu, 6 Jul 2017 17:49:46 -0400 (EDT) |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:54.0) Gecko/20100101 Firefox/54.0 |
Follow-up Comment #2, bug #51403 (project octave):
Part of the slowness of __isequal__ may be that it is written to always
support variable arguments, while the most common case is just two arguments
being compared.
Compare the timings and the profiler output for these two ways of testing
whether two objects have the same class:
>> x = [];
>> y = x;
>> profile on
>> tic; for i=1:10000; strcmp (class (x), class (y)); endfor; toc
Elapsed time is 0.180546 seconds.
>> profile off
>> profshow
# Function Attr Time (s) Time (%) Calls
------------------------------------------------------------------
2 class 0.015 75.92 20000
3 strcmp 0.005 23.51 10000
5 profile 0.000 0.40 1
4 toc 0.000 0.07 1
1 tic 0.000 0.02 1
6 nargin 0.000 0.02 1
8 false 0.000 0.02 1
7 binary != 0.000 0.02 1
9 __profiler_enable__ 0.000 0.00 1
>> profile clear
>> arg_list = {y};
>> profile on
>> tic; for i=1:10000; strcmp (class (x), cellfun ("class", arg_list,
"uniformoutput", false)); endfor; toc
Elapsed time is 0.330531 seconds.
>> profile off
>> profshow
# Function Attr Time (s) Time (%) Calls
------------------------------------------------------------------
4 cellfun 0.063 58.65 10000
5 strcmp 0.019 17.48 10000
2 class 0.016 15.16 20000
3 false 0.009 8.63 10001
7 profile 0.000 0.05 1
6 toc 0.000 0.01 1
1 tic 0.000 0.00 1
8 nargin 0.000 0.00 1
9 binary != 0.000 0.00 1
10 __profiler_enable__ 0.000 0.00 1
For the most common case of `isequal(x,y)`, y is still represented as varargin
and all comparisons are done using cellfun.
_______________________________________________________
Reply to this item at:
<http://savannah.gnu.org/bugs/?51403>
_______________________________________________
Message sent via/by Savannah
http://savannah.gnu.org/