Thx for your constructive remarks. I added the help as requested.
Your growdata function is quite nice, but serves a different purpose. The
advantage of the buffer class is to be able to store matrices which have to
match in only one dimension. Storing a matrix or multiple vectors at a time is
not possible with growdata.
Try doing your benchmark with larger amounts of data. The buffer class will
have the same execution time like with small data chunks. The execution time
of growdata increases.
---------
>> test
Parameters: iterations=25000 chunk size=3
buffer
Elapsed time is 7.491122 seconds.
growdata
Elapsed time is 1.268556 seconds.
Parameters: iterations=250 chunk size=300
buffer
Elapsed time is 0.007169 seconds.
growdata
Elapsed time is 0.172727 seconds.
Rule number 1: If you place something on the file exchange that does exactly the same thing as an existing code that is already there, at least do a better job at what it does. This fails rule number 1, and fails it miserably. It uses 4 functions to do the job that growdata or growdata2 do with one single function. It is much slower. Test it out:
% initialization
b = buffer
b: buffer with 0 elements.
{}
% growth
tic,for i=1:25000,b=store(b,rand(1,3));end,toc
Elapsed time is 104.959756 seconds.
% unpacking
tic,data = flush(b,1);toc
Elapsed time is 0.145784 seconds.
size(data)
ans =
25000 3
In comparison, try growdata2.
% initialization step
funh = growdata2;
% growth
tic,for i=1:25000,funh(rand(1,3));end,toc
Elapsed time is 3.101270 seconds.
% the unpacking step
tic,data = funh();toc
Elapsed time is 0.011790 seconds.
size(data)
ans =
25000 3
An interesting feature of these buffer tools is the time required to run them grows quadratically. Store twice as much, and the time grows by a factor of 4. The growdata tools are much closer to linear in the time required. Again, a test will show this nicely.
b = buffer;
tic,for i=1:5000,b=store(b,rand(1,3));end,toc
Elapsed time is 2.621039 seconds.
b = buffer;
tic,for i=1:10000,b=store(b,rand(1,3));end,toc
Elapsed time is 13.128627 seconds.
funh = growdata2;
tic,for i=1:25000,funh(rand(1,3));end,toc
Elapsed time is 3.108313 seconds.
funh = growdata2;
tic,for i=1:50000,funh(rand(1,3));end,toc
Elapsed time is 6.182426 seconds.
Rule number 2: Document your code. This set of tools has absolutely no help. You need to edit the functions just to figure out how to use them. When you use the help facility, you get this very unenlightening piece of information:
help buffer
buffer class
author: jan wolff, 2007
Rule number 3: At the very least, acknowledge the existing code. This submission does not do so.