i have 3 files x.lua, y.lua and main.lua. These files doing some mathematics operations (increment and decrement number). When i run the command
lua main.lua
is much faster than
luac -o main.luac -s x.lua y.lua main.lua
Please can you help me why is bytecode slower?
-
We need examples files that show the problem.Doub– Doub2014年03月26日 16:57:50 +00:00Commented Mar 26, 2014 at 16:57
2 Answers 2
I'm guessing that main.lua does dofile("x.lua") or require"x" and the same for y.lua.
In that case, the second form runs x.lua and y.lua twice.
Comments
They are very different operations:
lua main.lua: this does- reads 3 files,
- compiles them to bytecode in memory and
- executes a subset of their bytecode;
luac -o main.luac -s x.lua y.lua main.lua: this does:- reads 3 files (the 2 read by main are not read since main is not executed),
- compiles them to bytecode in memory, then
- saves three of them to one file on disk.
Writing a file (operation 2) is a slow operation, involving disk access, dumping memory chunks etc; it will be significantly slower than executing some bytecode (operation 1), unless latter is compute intensive.