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

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

[Octave-bug-tracker] [bug #58564] classdef instance field access painful


From: Rik
Subject: [Octave-bug-tracker] [bug #58564] classdef instance field access painfully slow vs. struct field access
Date: Mon, 15 Jun 2020 16:26:00 -0400 (EDT)
User-agent: Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko

Follow-up Comment #2, bug #58564 (project octave):

I ran another configuration where I converted the class object to a struct
first, and then use direct field access.

Code is


%% Convert to struct and then use direct . access
warning ("off", "Octave:classdef-to-struct");
sum = struct (obj).foo;
tic;
for i=1:iters
  sum = sum + struct (obj).foo;
end
dt = toc*1e6/iters - loop_overhead;
fprintf('%s: struct(obj).field access time = %.3f usec\n', class(obj), dt);


Results are


octave:7> field_access_timing
struct: obj.field access time = 1.183 usec 
struct: struct(obj).field access time = 5.350 usec
struct: obj.('field') access time = 1.675 usec
struct: subsref(obj,struct) access time = 5.937 usec

value_class: obj.field access time = 5.471 usec 
value_class: struct(obj).field access time = 14.032 usec
value_class: obj.('field') access time = 5.375 usec
value_class: subsref(obj,struct) access time = 10.259 usec

handle_class: obj.field access time = 6.119 usec 
handle_class: struct(obj).field access time = 15.243 usec
handle_class: obj.('field') access time = 7.334 usec
handle_class: subsref(obj,struct) access time = 13.133 usec


Clearly it is no help, but it is suggestive that running


struct (value_class).field


has nearly the same run time as calling 


struct (struct).field


It may be that internally the classdef object is being converted to a struct
before accessing the field members.  That's just a wild guess, have to check
the code in libinterp/octave-value.


    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?58564>

_______________________________________________
  Message sent via Savannah
  https://savannah.gnu.org/




reply via email to

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