lua-users home
lua-l archive

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


Hello all members,

This is my first post here so forgive me :)


II'm trying to port some code from python to lua on "embeded" device
(only 64MB RAM, 400 MHz MIPS32 CPU). One of its functions is to
calculate md5 sum from first 10MB of file.
The issue is that lua version is at least 10 times slower than python
version. It is looks like this is somehow relate to how lua io:read
reads file.
If I reduce read size to 1MB - lua is faster and result is the same -
but 10MB read in lua is nightnmare :(

Python code looks like this (most important part):
-----------
d=md5()
d.update(open(file).read(10485760))
return d
-----------

My Lua code looks like this:
-----------
local fh,err = io.open(fname)
return fh and md5.sumhexa(io.open(fname,"rb"):read(10485760)) or nil
----------

A made some research with strace it looks like lua is reading file
different that python and python read file like this:
[cut]
read(3, "\32E\337\243\223B\202\210matroskaB\207\201\2B\205\201\2\30S\200g\1\0\0\0"...,
10485760) = 10485760
close(3)                                = 0

but lua like this:
read(4, "\32E\337\243\223B\202\210matroskaB\207\201\2B\205\201\2\30S\200g\1\0\0\0"...,
4096) = 4096
brk(0x421000)                           = 0x421000
read(4, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"...,
4096) = 4096
brk(0x422000)                           = 0x422000
read(4, "m\266\333\n\361\362\0\356\356\366\330dS\352\355u\240\242\36\fi]k)\252L\320\260\0\20\0\0"...,
4096) = 4096
brk(0x423000)                           = 0x423000
read(4, "\317\233`\0\0\0006\330\0\330\0\356\330\20\333\273\347\207`\0mkZ\327\315mv\276}\372\2\3"...,
4096) = 4096
brk(0x424000)                           = 0x424000
read(4, "\1\0\0\10\0\0\0\r\355\300P\241^8>\0\200\0\0\7\217\300\0\1\0\4\0\f
\0\2\0"..., 4096) = 4096
brk(0x425000)                           = 0x425000
read(4, "\306\326\"\237\276h\335l]\3500\0\0\0\0@\34\0\0\33v\0\1\0\300\0\4\1\0\0\0\2"...,
4096) = 4096
brk(0x426000)                           = 0x426000
read(4, "\271\r\3747\301\3743[\245\266\215N\266F\220\202\217A\0\0\0\3m\275\273\1\343\307\315\266\333\2"...,
4096) = 4096
brk(0x427000)                           = 0x427000

Is there some way to speed up this issue ??
(I tried file:setvbuf option but it doesn't help at all)

Best regards and thanks in advance.


-- 
Marcin,