lua-users home
lua-l archive

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


On Fri, Mar 23, 2012 at 5:07 AM, Leo Razoumov <slonik.az@gmail.com> wrote:
> On Thu, Mar 22, 2012 at 22:31, David Manura <dm.lua@math2.org> wrote:
>> times (on x86 Xeon) [cygwin]:
>> 5.1.4:          1.8 1.8 1.8 s
>> 5.2.0:          3.1 3.1 3.1 s
>> 5.2.1-work1: 3.4 3.4 3.4 s
>
> So, on x86 Xeon lua-5.2.x is about twice slower than lua-5.1.4. What gives?

it turns out, luabalanced.gsub was never optimized on large files, and
it had the O(N^2) string concatenation problem.  Here's a simpler test
case of the problem:

  local text = io.open"all.lua":read"*a"
  local s = ''
  for i=1,2 do
    text:gsub('%S+', function(c) s = s .. c end)
  end

For some reason (maybe gc), lua-5.1.5/4 on Cygwin/gcc (4.5.3 & 3.4.4)
is much faster running that code than other combinations of Lua
versions (e.g. 5.2.0 and 5.2.0-work1) and compilers (e.g. mingw and
msvc) on the same system:

cygwin gcc-4.5.3 x86
lua-5.1.5  12.5 s <---- !!!
lua-5.2.0  22.0 s
lua-5.2.1-work1 16.0 s

mingw gcc-4.5.3 x86
lua-5.1.5  17.5 s
lua-5.2.0  18.5 s
lua-5.2.1-work1  20.5 s

msvc x86
lua-5.1.5 18.5 s
lua-5.2.0 18.0 s
lua-5.2.1-work1 18.5 s

After fixing luabalanced, the test cited at the top of this post
(after increasing the iterations from 3 to 100 to account for the much
faster speed) now gives similar results in both mingw and cygwin:

lua-5.1.5       4.0 s
lua-5.2.0       4.8 s
lua-5.2.1-work1  4.7 s