[Scilab-users] Ways to speed up simple things in Scilab ?

Tim Wescott tim at wescottdesign.com
Fri Apr 24 18:53:31 CEST 2015


If A stays constant this should work well.

Yes, doing this as a C call will speed things up, too, but if you can do
it with matrices and no C calls your code may stand the test of time
better.

What seems to work for me is to keep in mind that Scilab tends to be
slow with individual operations, but without much of a speed hit for
matrix operations.  So any place that you can replace a 'for' loop or
string of statements with a matrix operation, you can save time.

On Fri, 2015-04-24 at 14:50 +0200, Stéphane Mottelet wrote:
> Hello Antoine 
> 
> 
> I think your idea is excellent in my context, I Will try it and keep
> you informed of the actual improvement,
> 
> 
> S.
> 
> Le 24 avr. 2015 à 13:31, Antoine Monmayrant
> <antoine.monmayrant at laas.fr> a écrit :
> 
> 
> > Hi again,
> > 
> > Another way you might improve your code: can you write it as a
> > matrix-vector product?
> > Like
> > 
> > M1_v=A*v; 
> > Where A is a matrix of size (839,172) that corresponds to your weird
> > combination of v(i) to build M1_v.
> > It seems to me that you should be able to write it that way, which
> > would save a lot of time as matrix product are fast in Scilab.
> > 
> > Antoine
> > 
> > 
> > Le 04/23/2015 11:51 PM, Stéphane Mottelet a écrit :
> > 
> > > Hello, 
> > > 
> > > I am currently working on a project where Scilab code is
> > > automatically generated, and after many code optimization, the
> > > remaining bottleneck is the time that Scilab spends to execute
> > > simple code like this (full script (where the vector has 839
> > > lines) with timings is attached) : 
> > > 
> > > M1_v=[v(17) 
> > > v(104) 
> > > v(149) 
> > > -(v(18)+v(63)+v(103)) 
> > > -(v(18)+v(63)+v(103)) 
> > > v(17) 
> > > ... 
> > > v(104) 
> > > v(149) 
> > > ] 
> > > 
> > > This kind of large vectors are the used to build a sparse matrix
> > > each time the vector v changes, but with a constant sparsity
> > > pattern. Actually, the time spent by Scilab in the statement 
> > > 
> > > M1=sparse(M1_ij,M1_v,[n1,n2]) 
> > > 
> > > is negligible compared to the time spent to build f M1_v... 
> > > 
> > > I have also noticed that if you need to define such a matrix with
> > > more that one column, the time elapsed is not linear with respect
> > > to the number of columns: typically 4 times slower for 2 columns.
> > > In fact the statement 
> > > 
> > > v=[1 1 
> > > ... 
> > > 1000 1000] 
> > > 
> > > is even two times slower than 
> > > 
> > > v1=[1 
> > > ... 
> > > 1000]; 
> > > v2=[1 
> > > .... 
> > > 1000]; 
> > > v=[v1 v2]; 
> > > 
> > > So my question to users who have the experience of dynamic link of
> > > user code : do you think that using dynamic link of compiled
> > > generated C code could improve the timings ? 
> > > 
> > > In advance, thanks for your help ! 
> > > 
> > > S. 
> > > 
> > > 
> > > 
> > > 
> > > _______________________________________________
> > > users mailing list
> > > users at lists.scilab.org
> > > http://lists.scilab.org/mailman/listinfo/users
> > 
> > 
> > 
> > _______________________________________________
> > users mailing list
> > users at lists.scilab.org
> > http://lists.scilab.org/mailman/listinfo/users
> > 
> _______________________________________________
> users mailing list
> users at lists.scilab.org
> http://lists.scilab.org/mailman/listinfo/users

-- 

Tim Wescott
www.wescottdesign.com
Control & Communications systems, circuit & software design.
Phone: 503.631.7815
Cell:  503.349.8432




More information about the users mailing list