lua-users home
lua-l archive

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


> -----Original Message-----
> From: Bas Groothedde [mailto:lua@xoru.net]
> Sent: zaterdag 18 mei 2013 16:34
> To: Thijs Schreijer
> Subject: RE: Filling multiple tables in one loop
> 
> On 18.05.2013 16:07, Thijs Schreijer wrote:
> > Wouldn't it be cheaper to perform the min/max test first, and then
> duplicate the element on the stack (lua_pushvalue) instead of calling
> lua_pushnumber twice? (with 10000 elements that should be easy to test)
> 
> Thijs
> That's a very good point, but the actual function I want to apply this to
> is a prime sieve function, the Sieve of Eratosthenes.
> This specific siever that fills two tables, fills one table with prime
> numbers within the range, and the other table is a lookup
> table where i is a number and v is a boolean stating if i is a prime.
> This means that table one consists of numbers and table two consists of
> booleans, would pushvalue be useful in this situation?
> Thanks,
> Bas

In that case no, because lua_pushvalue duplicates a value already on the stack. And as you need two different values, it won't help you speed things up.

Thijs