attractivechaos / plb

Programming language benchmarks
http://attractivechaos.github.com/plb/
272 stars 57 forks source link

Looks like patmch Lua implementation needs some collectgarbage() calls. #15

Closed agladysh closed 11 years ago

agladysh commented 11 years ago

Something along these lines:

-- These aliases would help plain Lua.
local io_lines = io.lines
local print = print -- Consider removing IO from all benchmarks, BTW.
local collectgarbage = collectgarbage

local pattern = (...)

local counter = 0
for l in io_lines() do
  if l:find(pattern) then print(l) end

  counter = counter + 1
  if counter % 1000 == 0 then -- Play with this value
    collectgarbage("step")
    counter = 0
  end   
end

I'll submit a pull request if you'd do #14.

attractivechaos commented 11 years ago

Using collectgarbage() makes no difference at all. Honestly, I think local print = print is over-optimization. That is not the way most Lua programmers write Lua. Also, I/O is not necessarily bad as long as it is not the bottleneck. It is not in this case and in the dictionary benchmark, in theory. (I will come to issue #13 later about this topic)

agladysh commented 11 years ago

Hmm, that is interesting. No difference — even for plain Lua?

attractivechaos commented 11 years ago

LuaJIT only. Haven't tried Lua.

agladysh commented 11 years ago

Well, local aliases are an optimization for plain Lua, as I stated in the comment.

attractivechaos commented 11 years ago

For plain Lua, slower with collectgarbage. EDIT: at least not faster.

agladysh commented 11 years ago

That is not the way most Lua programmers write Lua.

"Most" is arguable. We have about 600KLOC written in this style.

Note that the performance is not the only reason. If you do not do aliasing, your code wouldn't work in the sandbox with a custom global environment.

Couple of links from three seconds of googling:

agladysh commented 11 years ago

For plain Lua, slower with collectgarbage. EDIT: at least not faster.

OK, this means that I misinterpreted that 999. See #18.

attractivechaos commented 11 years ago

Ok. I buy your argument. But anyway, no improvement to speed.

agladysh commented 11 years ago

Ok. I buy your argument. But anyway, no improvement to speed.

Even not for plain Lua? Strange. Thanks for trying, anyway.