lua-users home
lua-l archive

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


hello Joseph

On Fri, Jan 21, 2011 at 12:04 PM, Joseph Manning <manning@cs.ucc.ie> wrote:

>>>         for kk = k*2, max, k do

> faster :   for kk = k*k, max, k do

does it mean k*k is faster than k*2 ?

I've tried with the  script below, and i find the opposite to be true
by +10% , on Lua5.1 at least.

k=100
local x = os.clock()
local s = 0
for i=1,1000000 do kk=k*k end
print(string.format("elapsed time: %.6f\n", os.clock() - x))
local x = os.clock()
local s = 0
for i=1,1000000 do kk=k*2 end
print(string.format("elapsed time: %.6f\n", os.clock() - x))