Skip to content

Commit

Permalink
Re #1786 improvements in search when fast_map is not optimized.
Browse files Browse the repository at this point in the history
  • Loading branch information
abuts committed Feb 11, 2025
1 parent f58540a commit 7469c96
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
9 changes: 5 additions & 4 deletions _test/test_utilities_herbert/fast_map_vs_map_performance.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
n_keys = 500;
n_keys = 200;
base_key = 10+round(rand(1,10*n_keys)*(10*n_keys-1));
base_key = unique(base_key);

Expand All @@ -7,7 +7,7 @@
keysUint = uint32(base_key);
mm = min_max(keysUint)

n_operations= 100000;
n_operations= 40000;


test_keys = repmat(base_key,1,n_operations);
Expand Down Expand Up @@ -53,9 +53,10 @@
fprintf('Find keys in FAST MAP map takes %gsec\n',tv)

tv = tic;
fm.optimized = false;
idx1 = fm.get_values_for_keys(test_keys);
tv = toc(tv);
fprintf('Find all keys in FAST MAP map takes %gsec\n',tv)
fprintf('Find all keys in FAST MAP non-opt takes %gsec\n',tv)


fm.optimized = true;
Expand All @@ -64,7 +65,7 @@
idx1 = fm.get(test_keys(i));
end
tv = toc(tv);
fprintf('Find keys in FAST MAP Opt map takes %gsec\n',tv)
fprintf('Find keys in FAST MAP opt map takes %gsec\n',tv)
fm = fast_map(test_keys,1:numel(test_keys));
fm.optimized = true;
tv = tic;
Expand Down
20 changes: 13 additions & 7 deletions herbert_core/utilities/classes/@fast_map/fast_map.m
Original file line number Diff line number Diff line change
Expand Up @@ -210,13 +210,10 @@
val(idx) = kvo(keys(idx)-kvs);
end
else

for idx=1:numel(keys)
present = self.keys_ == key(idx);
if any(present)
val(idx) = self.values_(present);
end
end
ks = self.keys_;
requested = ismember(ks,key);
kv = self.values_;
val = kv(requested);
end
end

Expand Down Expand Up @@ -260,6 +257,15 @@
% reason, until, may be mex is written which would deal with fast part
% of indices or we fully switch to MATLAB over 2021a, where you may
% overload subsagn using inheritance and specified abstract methods.
% SAMPLE OF PERFORMANCE OF fast_map vrt MATLAB map (UINT map)
% subsref/subsasgn : enabled ! disabled
%Find & Add keys to UINT map takes: 108.82sec ! 106.53sec
%Find & Add keys FAST MAP map takes: 372.73sec ! 6.75sec
%Find keys in UINT map takes: 29.36sec ! 29.46sec
%Find keys in FAST MAP map takes: 183.09sec ! 5.28sec
%Find all keys in FAST MAP non-opt takes: 0.14sec ! 0.14sec
%Find keys in FAST MAP opt map takes: 180.73sec ! 0.23sec
%Find all keys in FAST MAP opt map takes: 0.045sec ! 0.038sec
methods
% function varargout = subsref(self,idxstr)
% if ~isscalar(self) % input is array or cell of unique_object_containers
Expand Down

0 comments on commit 7469c96

Please sign in to comment.