lua-users home
lua-l archive

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


On Thu, 14 Aug 2014 11:33:41 +0100
"Joseph Manning" <manning@cs.ucc.ie> wrote:

> On 2014-Aug-14 (Thu) at 03:23 (+0200), Jan Behrens wrote:
> 
> >> If Lua's built-in O(log n) length operator is really that fast, then
> >> caching the length might not make sense in my case.
> 
> Jan,
> 
>    At one stage, I was also concerned about evaluating #t several times
>    for the same table, and considered caching this value for efficiency,
>    even at the cost of a slight code obfuscation.
> 
>    So I ran a simple benchmark.
> 
>    For a table t with 10,000 elements, I found that #t can be calculated
>    1,000,000 times in under 0.1 seconds.  And on a 6-year-old "netbook".
> 
>    So you probably need not worry about re-evaluating #t.  It's fast.
> 
> Joseph
> 
> PS: the above was with Lua 5.2

I believe that Lua's # operator is fast :-)

But my issue is not just about the speed of the built-in # operator.

(See my previous post from Thu, 14 Aug 2014 13:09:10 +0200)


Regards
Jan