[Scilab-users] Large variables and execution speeds
Samuel Gougeon
sgougeon at free.fr
Sun Mar 1 21:05:30 CET 2015
Tim,
Using global variables as well saves time.
Here attached is Clement's bench tests extended to global variables and
global lists.
Typical results on my PC are (in [s]) :
-->exec('C:\computation.sci', -1)
local LISTS: not assigned: 0.34 create recipient: 1.362 assign2
existing recipent: 1.116
local vars: not assigned: 0.41 create recipient: 0.512 assign2
existing recipent: 0.502
Global vars: not assigned: 0.34 create recipient: 0.96 assign2
existing recipent: 0.34
Global LISTS: not assigned: 0.34 create recipient: 0.7 assign2
existing recipent: 0.32
By the way, AFAIK, graphical handles are global objects passed by
reference. Clement, aren't they?
It is possible to hide some data in their .userdata field ; but it is
somewhat hacking, and it could be tricky to avoid creating explicitly or
implicitly local copies of this field's content when working with it...
Creating a pseudo graphic with output driven to "null" and then using
this hack could extend the test bunch ;)
Regards
Samuel
Le 24/02/2015 22:38, Tim Wescott a écrit :
> I have an algorithm that I'm working on that involves having large data
> sets, which I'm currently representing as tlists. Due to the
> constraints of the algorithm, I'm doing many calls that are more or less
> of the form:
>
> my_tlist = some_function(my_tlist);
>
> The intent is to get the same effect that I would get if I were in C or
> C++, and wrote:
>
> some_function(& my_structure);
>
> or
>
> my_class.some_function();
>
> It appears, from the significant loss of execution speed when I do this,
> that Scilab is copying the results of the function into the "my_tlist"
> variable byte by byte.
>
> At this writing, the only way that I can see to fix this is to invoke
> the function as:
>
> some_function("my_tlist");
>
> and then wherever I modify data have use an exec function, i.e., replace
>
> local_tlist.some_field = stuff;
>
> with
>
> exec(msprintf("%s = stuff", local_tlist_name));
>
> This seems clunky in the extreme.
>
> Is there another way to do something like this that doesn't force Scilab
> to copy large chunks of data needlessly, but allows me to operate on
> multiple copies of similar tlists?
>
> Thanks.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20150301/1058b62a/attachment.htm>
-------------- next part --------------
stacksize('max');
fp = funcprot();
funcprot(0);
// using tlist
data = tlist(['mydata' 'foo' 'bar' 'zero'], [], [], []);
data.foo = zeros(4096,4096);
data.bar = ones(4096,4096);
function data=computation(data)
data.zero = data.foo + data.bar
endfunction
tic();
data.foo + data.bar;
cost=toc();
tic();
data = computation(data);
cost_resize=toc();
tic();
data = computation(data);
cost_not_resize=toc();
printf("local LISTS:\t not assigned: %g create recipient: %g assign2 existing recipent: %g\n",..
cost, cost_resize, cost_not_resize);
clear data
// using variables
foo = zeros(4096,4096);
bar = ones(4096,4096);
function [zero]=computation(foo, bar)
zero = foo + bar
endfunction
tic();
foo + bar;
cost=toc();
tic();
zero = computation(foo, bar);
cost_resize=toc();
tic();
zero = computation(foo, bar);
cost_not_resize=toc();
printf("local vars:\t not assigned: %g create recipient: %g assign2 existing recipent: %g\n",..
cost, cost_resize, cost_not_resize);
clear foo bar zero
// using global variables
// ----------------------
global foo Bar resu
foo = zeros(4096,4096);
Bar = ones(4096,4096);
function computation()
global foo Bar resu
resu = foo + Bar
endfunction
tic();
foo + Bar;
cost = toc();
tic();
computation();
cost_create_resu = toc();
tic();
computation();
cost_not_resize = toc();
printf("Global vars:\t not assigned: %g create recipient: %g assign2 existing recipent: %g\n",..
cost, cost_create_resu, cost_not_resize);
clearglobal foo Bar resu
// using a global tlist
global data
data = tlist(['mydata' 'foo' 'bar' 'zero'], [], [], []);
data.foo = zeros(4096,4096);
data.bar = ones(4096,4096);
function computation()
global data
data.zero = data.foo + data.bar
endfunction
tic();
data.foo + data.bar;
cost=toc();
tic();
computation();
cost_resize=toc();
tic();
computation();
cost_not_resize=toc();
printf("Global LISTS:\t not assigned: %g create recipient: %g assign2 existing recipent: %g\n",..
cost, cost_resize, cost_not_resize);
clearglobal data
funcprot(fp);
More information about the users
mailing list