[OT -- not fpc-related -- just a side note]
On Fri, 7 May 2010 00:34:11 +0200
Jonas Maebe <[email protected]> wrote:
> in general my bias would be much more against than in favour of global
> variables from a speed perspective
In _some_ dynamic languages using a virtual machine at least (eg Lua), local
variables are actually stored in an array, after a one->one replacement from
name to index at "compile"-time. While global ones are still looked up in a
symbol table (associative array implemented as hash table) by name.
This indeed makes some speed difference ;-) (~ 50% in Lua) For instance:
<code lang=lua>
require "os" ; time = os.time
format = string.format
N = 333333333
f = function()
a = 1 -- implicitely global
local b = 0
for i = 1,N do b=a end
end
g = function()
local a = 1
local b = 0
for i = 1,N do b=a end
end
-- global case
t = time()
f()
t = time() - t
print(format("global : %2.0fs", t)) -- 25s
-- local case
t = time()
g()
t = time() - t
print(format("local : %2.0fs", t)) -- 13s
</code>
Denis
________________________________
vit esse estrany ☣
spir.wikidot.com
_______________________________________________
fpc-pascal maillist - [email protected]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal