lua-users home
lua-l archive

Storing state information (was Re: Ah, those uninitiated people...)

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Jan 14, 2010, at 7:15 AM, Mark Hamburg wrote:
> While upvalues are slower than locals, I suspect that a table lookup is slower still.
Some statistics. This basically is the result of timing a loop that counts up to a really big number using various ways of storing the counter.
Lua 5.1.4:
	Local	 98.276374
	Upvalue (open) 209.396356
	Upvalue	(closed) 216.251567
	Table field 561.369677
	Global			 612.179566
So, locals are a clear win. I'm interested that tables are a win relative to globals. Presumably this has to do with the table being smaller. Or else there's a lot of overhead in the opcodes to get and set globals.
LuaJIT levels the playing field.
LuaJIT 2.0:
	Local 11.21
	Upvalue (open) 11.31
	Upvalue (closed) 11.18
	Table field		11.15
	Global			11.36
Lua 5.2 (work1) is also definitely a bit slower:
Lua 5.2 (work1):
	Local	 107.266672
	Upvalue (open) 223.447284
	Upvalue	(closed) 222.159344
	Table field 620.652007
	Global			 677.802486
Mark

AltStyle によって変換されたページ (->オリジナル) /