lua-users home
lua-l archive

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

>>> 01/29/03 11:00 AM >>>
>>I modified the timing code to use x:fact(10) and the 
>>time was slightly FASTER at 8.44 seconds.

> Probably because now you're indexing a local variable 
> ("self")...
> Try
>     local function fact(n)
> in the original code...
> --lhf

Actually, I think there's more to it. While 'self' is a  local variable,
it is a table itself, and 'fact' is looked up in that table.

Moreover, the 'self' table is an empty table. Each lookup of 'fact'
should require:

    lookup 'fact' in 'self' which fails
    check for a metatable, which exists
    lookup __index in the metatable
    since __index is a table, lookup 'fact' there

I assumed the small increase in speed was due to the size of the tables
involved. Or am I missing something?

   - Tom