lua-users home
lua-l archive

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


Although I have been using Lua for 5 years, I only recently started to
use LuaJIT for image processing tasks.
My observation is that LuaJIT along with FFI for direct byte access is
just incredibly fast, comparable to my C++ reference implementation!

Today, during the implementation of a bitmap rotation, I saw a strange
timing behavior. The first test loops are extremely fast, but the next
ones are really slow.
I have tried the code with LuaJIT 2.0 git HEAD, compiled on Windows
using MSVC 32 bits, MSVC 64 bits, and Cygwin 32 bits. The behavior is
the same in all cases.
The test code below is a very very simplified portion of my code, but
it still shows the problem:

function Test()
	local function Internal()	
	end
	for i=0,10000000 do
		Internal()
	end
end

for i=1,1000 do
	local t = os.clock()
	Test(pdst)
	print(("Test %d in %5.3f s"):format(i, os.clock() - t))
end


The test output looks like this on my machine:
.....
Test 93 in 0.004 s
Test 94 in 0.004 s
Test 95 in 0.004 s
Test 96 in 0.003 s
Test 97 in 0.004 s
Test 98 in 0.004 s
Test 99 in 0.004 s
Test 100 in 0.004 s
Test 101 in 0.003 s
Test 102 in 1.683 s
Test 103 in 1.682 s
Test 104 in 1.683 s

The 101 first loops only take 4 ms, while the next ones take 1.68 s,
so suddenly 420 times more!
How can this happen?