[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Realtime cost of call by value
From: |
taltman |
Subject: |
Re: Realtime cost of call by value |
Date: |
Tue, 28 Oct 2003 23:41:13 +0000 (UTC) |
Hi Glenn,
I just did a set of timing tests, and I believe that there might be
some fundamental difference. I'm not hard core enough ( yet ) to delve
into the interpreter source code to find out for sure, but these tests
tell me that "global" is indeed just allowing copying to occur between
scopes.
Below, please find the mangled code that I used to test my
hypothesis. Just type, for example:
globalpasstestDriver(1,100)
To get a graph showing the normalized difference between an average of
10 "function calls", for passing a matrix of side length 1 through
100, to two different functions, one via pass-by-value, and one via
pass-by-global-variable.
There appears to be a certain polynomial power > 1 by which the
normalized difference grows.
I tried to take pains to make sure that I was truly only timing the
function call, but I might have bungled it. Please feel free to rip
into it.
I think that there were hints that newer versions of Octave will
have "handles", or "references" to data. Any news regarding that,
John?
~Tomer
---
function PassByGlobalScope
global aMatrix;
aMatrix(1,1) = rand(1);
endfunction
function someMatrix = PassByValue ( someMatrix )
someMatrix(1,1) = rand(1);
endfunction
function [ avg_runtime ] = globalpasstest ( size, scope_bool )
global aMatrix = rand(size);
sum_runtime = 0;
if ( scope_bool )
for i=1:10
tic;
PassByGlobalScope;
sum_runtime = sum_runtime + toc;
aMatrix = rand(size);
endfor
else
for i=1:10
tic;
PassByValue(aMatrix);
sum_runtime = sum_runtime + toc;
aMatrix = rand(size);
endfor
endif
i = 0;
avg_runtime = sum_runtime / 100;
endfunction
function globalpasstestDriver ( min, max )
x = min:max;
#size(min:max);
y = zeros(1,(max-min+1));
#size(y);
z = zeros(1,(max-min+1));
#size(z);
for i=1:(max-min+1)
y(i) = globalpasstest(i,1);
z(i) = globalpasstest(i,0);
endfor
[ yrows, ycols ] = size(y);
[ zrows, zcols ] = size(z);
mplot(x,(z-y)./y,"1")
endfunction
-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.
Octave's home on the web: http://www.octave.org
How to fund new projects: http://www.octave.org/funding.html
Subscription information: http://www.octave.org/archive.html
-------------------------------------------------------------
- Realtime cost of call by value, Glenn Golden, 2003/10/27
- Re: Realtime cost of call by value, Glenn Golden, 2003/10/28
- Re: Realtime cost of call by value, Glenn Golden, 2003/10/28
- Re: Realtime cost of call by value,
taltman <=
- Re: Realtime cost of call by value, Glenn Golden, 2003/10/29
- Re: Realtime cost of call by value, taltman, 2003/10/29
- Re: Realtime cost of call by value, Glenn Golden, 2003/10/29
- Re: Realtime cost of call by value, John W. Eaton, 2003/10/29
- Re: Realtime cost of call by value, Glenn Golden, 2003/10/29
- Re: Realtime cost of call by value, John W. Eaton, 2003/10/29
- Re: Realtime cost of call by value, Glenn Golden, 2003/10/30