Hello Stephane,

You can speed up by a factor larger than 100 just by calling v once (or 3 times) instead of ~1000, as shown by this test:

function  test2()
   // part 1 : only 1 call to v
    v  =  rand(172,1);
    p  =  grand(1,839,"unf",1,173)
    tic()
    for  i=1:1000
        m1_v  =  v(p)
    end
    disp(toc())

   // part 2 : 839 calls to v
   e  =  "M1_v = ["+strcat("v("+string(p)+")")+"]"
    tic()
    for  i=1:1000
        execstr(e)
    end
    disp(toc())

   // part 3 : calls to "empty" execstr(), to be substrated from the previous 
result
   e  =  "M1_v = 0";
    tic()
    for  i=1:1000
        execstr(e)
    end
    disp(toc())
endfunction

On my PC, i get:
-->test2

    0.015

    1.888

    0.015

So, you do not really need to go to compiled solutions, just to rewrite 839 lines into ~10 lines.

Regards
Samuel

Le 23/04/2015 23:51, 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@lists.scilab.org
http://lists.scilab.org/mailman/listinfo/users

_______________________________________________
users mailing list
users@lists.scilab.org
http://lists.scilab.org/mailman/listinfo/users

Reply via email to