<font size=2 face="sans-serif">Hello Stephane,</font>
<br>
<br><font size=2 face="sans-serif">We have a Scilab program which performs
a numerical integration on data points in 3-dimensions - it has two
nested loops. When the number of data points was large this was slow
so we implemented the calculation function in C and got a speed improvement
of about 24 times !</font>
<br>
<br><font size=2 face="sans-serif">We also found three other improvements:</font>
<br>
<br><font size=2 face="sans-serif"> using
pointer arithmetic was faster than 'for' loops,</font>
<br><font size=2 face="sans-serif"> 'pow(x,
2)' was faster than x*x,</font>
<br><font size=2 face="sans-serif"> handling
the data as 3 (N x 1) vectors was faster than using 1 (N x 3) matrix.</font>
<br>
<br><font size=2 face="sans-serif">each of these giving something like
a 3-4% improvement - small compared to x24 but still worth having.</font>
<br>
<br><font size=2 face="sans-serif">If you don't mind tackling the dynamic
linking it's probably worth the effort if you'll use this program a few
times - good luck.</font>
<br>
<br><font size=2 face="sans-serif">Adrian.</font>
<br><font size=2 face="sans-serif"><br>
</font>
<table>
<tr>
<td><font size=2 color=#2f2f2f face="Arial"><b>Adrian Weeks </b></font><font size=1 color=#5f5f5f face="Arial"><br>
Development Engineer, Hardware Engineering EMEA<br>
Office: +44 (0)2920 528500 | Desk: +44 (0)2920 528523 | Fax: +44 (0)2920
520178</font><font size=1 color=blue face="Arial"><u><br>
</u></font><a href=mailto:aweeks@hidglobal.com><font size=1 color=blue face="Arial"><u>aweeks@hidglobal.com</u></font></a><font size=1 color=#5f5f5f face="Arial"><br>
</font>
<tr>
<td><a href=http://www.hidglobal.com/><img src=cid:_1_05842B58058427580029358480257E31 width=312 height=48 alt="HID Global Logo"></a>
<tr>
<td><font size=1 color=#5f5f5f face="Arial">Unit 3, Cae Gwyrdd,<br>
Green meadow Springs,<br>
Cardiff, UK,<br>
CF15 7AB.</font><font size=1 color=blue face="Arial"><u><br>
</u></font><a href=http://www.hidglobal.com/><font size=1 color=blue face="Arial"><u>www.hidglobal.com</u></font></a></table>
<br>
<br>
<br>
<br>
<table width=100%>
<tr valign=top>
<td><font size=1 color=#5f5f5f face="sans-serif">From:</font>
<td><font size=1 face="sans-serif">Stéphane Mottelet <stephane.mottelet@utc.fr></font>
<tr valign=top>
<td><font size=1 color=#5f5f5f face="sans-serif">To:</font>
<td><font size=1 face="sans-serif">"International users mailing list
for Scilab." <users@lists.scilab.org></font>
<tr valign=top>
<td><font size=1 color=#5f5f5f face="sans-serif">Date:</font>
<td><font size=1 face="sans-serif">23/04/2015 22:52</font>
<tr valign=top>
<td><font size=1 color=#5f5f5f face="sans-serif">Subject:</font>
<td><font size=1 face="sans-serif">[Scilab-users] Ways to speed up simple
things in Scilab ?</font>
<tr valign=top>
<td><font size=1 color=#5f5f5f face="sans-serif">Sent by:</font>
<td><font size=1 face="sans-serif">"users" <users-bounces@lists.scilab.org></font></table>
<br>
<hr noshade>
<br>
<br>
<br><tt><font size=2>Hello,<br>
<br>
I am currently working on a project where Scilab code is automatically
<br>
generated, and after many code optimization, the remaining bottleneck is
<br>
the time that Scilab spends to execute simple code like this (full <br>
script (where the vector has 839 lines) with timings is attached) :<br>
<br>
M1_v=[v(17)<br>
v(104)<br>
v(149)<br>
-(v(18)+v(63)+v(103))<br>
-(v(18)+v(63)+v(103))<br>
v(17)<br>
...<br>
v(104)<br>
v(149)<br>
]<br>
<br>
This kind of large vectors are the used to build a sparse matrix each <br>
time the vector v changes, but with a constant sparsity pattern. <br>
Actually, the time spent by Scilab in the statement<br>
<br>
M1=sparse(M1_ij,M1_v,[n1,n2])<br>
<br>
is negligible compared to the time spent to build f M1_v...<br>
<br>
I have also noticed that if you need to define such a matrix with more
<br>
that one column, the time elapsed is not linear with respect to the <br>
number of columns: typically 4 times slower for 2 columns. In fact the
<br>
statement<br>
<br>
v=[1 1<br>
...<br>
1000 1000]<br>
<br>
is even two times slower than<br>
<br>
v1=[1<br>
...<br>
1000];<br>
v2=[1<br>
....<br>
1000];<br>
v=[v1 v2];<br>
<br>
So my question to users who have the experience of dynamic link of user
<br>
code : do you think that using dynamic link of compiled generated C code
<br>
could improve the timings ?<br>
<br>
In advance, thanks for your help !<br>
<br>
S.<br>
<br>
<br>
[attachment "test.sce" deleted by Adrian Weeks/CWL/EU/ITG] _______________________________________________<br>
users mailing list<br>
users@lists.scilab.org<br>
</font></tt><a href=http://lists.scilab.org/mailman/listinfo/users><tt><font size=2>http://lists.scilab.org/mailman/listinfo/users</font></tt></a><tt><font size=2><br>
</font></tt>
<br>
<br>