lua-users home
lua-l archive

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


On Thu, Mar 22, 2012 at 2:43 PM, KHMan <keinhong@gmail.com> wrote:
> (a) load data, parse, dump into two arrays [...]
> lua-5.2.0       0.261   0.274   0.285
> lua-5.2.1wk1
>  shortlen=16    0.180   0.188   0.204
>  shortlen=32 0.224 0.201   0.220

No difference in word count (wc): http://www.lua.org/pil/21.2.1.html .

Under more optimal contrived conditions, I can get ~50% speedup though:

-- $ dd if=/dev/urandom of=/tmp/random bs=1048576 count=100
local N = tonumber((...) or 33)
local fh = assert(io.open('/tmp/random', 'rb'))
local res = 0
local t = {}
while 1 do
  local data = fh:read(N)
  if not data then break end
  --data = data:gsub('%s', '') -- speed difference is smaller with this line
  res = res + data:byte(1)
  t[#t+1] = data  -- speed difference is smaller without this line
end
-- table.sort(t) -- speed difference is smaller with this line
print(res)