[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: ipairs in Lua 5.3.0-alpha
- From: "Joseph Manning" <manning@...>
- Date: Thu, 14 Aug 2014 11:33:41 +0100
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
------------------------------------------------------------------------
Joseph Manning / Computer Science / UCC Cork Ireland / manning@cs.ucc.ie
------------------------------------------------------------------------