lua-users home
lua-l archive

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


Roberto wrote:
> As a rule, you should always avoid using dostring if you can (it is too
> expensive). A better way to do what you want is with getglobal:


Yes, it is more expensive. On my machine (W2K 750MHz PIII) this code:

    for i=1,100000 do
        local f = getglobal("Test_Version")
        f()
    end

Executed in 0.12 seconds, while this code:


    for i=1,100000 do
        dostring("return Test_Version()")
    end

Executed in 1.262 seconds.

So about a factor of 10 slower. 

However, I have to say that 12.62 microseconds to execute the
"dostring" version is pretty darn fast, plenty fast enough for many
situations.

  - Tom Wrensch