Advertisement
Guest User

MATLAB cell/Map/Heterogeneous performance

a guest
Jan 14th, 2015
364
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.92 KB | None | 0 0
  1. %%%%%%%% FILE SomeHeterogeneousClass.m
  2. classdef SomeHeterogeneousClass < matlab.mixin.Heterogeneous
  3.     properties (Access=public)
  4.         data
  5.      end
  6.      methods (Access=public)
  7.         function this=SomeHeterogeneousClass(i)
  8.             this.data = i;
  9.         end
  10.      end
  11. end
  12.  
  13.  
  14. %%%%%%%%% FILE testMaps.m
  15.  
  16. function testMaps()
  17.     N = 65535;
  18.     timeBegin = tic();
  19.     m=containers.Map('KeyType', 'uint32', 'ValueType', 'uint32');
  20.     for (i = uint32(1:N))
  21.         m(i) = i;
  22.     end
  23.     fprintf('Maps took %.5d seconds.\n', toc(timeBegin));
  24.     whos m
  25.     clear m timeBegin;
  26.    
  27.     timeBegin = tic();
  28.     m=cell(N,1);
  29.     for (i = uint32(1:N))
  30.         m{i} = i;
  31.     end
  32.     fprintf('Cells took %.5d seconds.\n', toc(timeBegin));
  33.     whos m
  34.     clear m timeBegin;
  35.    
  36.     timeBegin = tic();
  37.     m=SomeHeterogeneousClass.empty(0,N);
  38.     for (i = uint32(1:N))
  39.         m(i) = SomeHeterogeneousClass(i);
  40.     end
  41.     fprintf('Heterogeneous array took %.5d seconds.\n', toc(timeBegin));
  42.     whos m
  43. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement