[Scilab-users] How to speed up making big structure?

Samuel Gougeon sgougeon at free.fr
Fri Jul 3 11:01:48 CEST 2015


Le 03/07/2015 09:42, jaipur a écrit :
> I'm making a big structure (about 110,000 items) by reading data from
> Hipparcos star catalog text file.
> My procedure is as follows.
>
> MyStruct = struct(); Index = 0;
> while ~meof(Fd) do
>       ........
>       ........
>       Index = Index + 1;
>       MyStruct(Index).Field1 = ...;
>       MyStruct(Index).Field2 = ...;
>       MyStruct(Index).Field3 = ...;
> end
>
> But this procedure takes huge time!!
> The number of items is known. Could you teach me speedy way to make big
> structure?
> For example, keep memory for structure before starting like
>
> MyVector = ones(110000,1);

*You must use Scilab 6*. Handling of structures is much faster and 
optimized with it:
// at increasing index:
-->clear s, tic; t=[]; for i=1:1000, s(i).n=%pi; if pmodulo(i,10)==0, 
t(i/10)=toc(); end, end, toc()
  ans  =
     0.7841965

// at decreasing index:
-->clear s, tic; t=[]; for i=1000:-1:1, s(i).n=%pi; if pmodulo(i,10)==0, 
t(i/10)=toc(); end, end, toc()
  ans  =
     0.391459

// at increasing index after initial sizing:
-->clear s, tic; t=[]; s(1000).n="abc"; for i=1:1000, s(i).n="abc"; if 
pmodulo(i,10)==0, t(i/10)=toc(); end, end, toc()
  ans  =
     0.413913

*Conclusion*: for structures arrays,
  - Scilab 6 (aka YaSp) is ~12 times faster than the best of Scilab 5.5.2
  - initializing the array size still makes things faster. It decreases 
by a factor ~2 the time to fill the array

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20150703/d9d79cf6/attachment.htm>


More information about the users mailing list