0

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?

miushock
1,1077 silver badges20 bronze badges
asked Mar 24, 2014 at 22:42
1
  • We need examples files that show the problem. Commented Mar 26, 2014 at 16:57

2 Answers 2

3

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.

answered Mar 25, 2014 at 0:08
Sign up to request clarification or add additional context in comments.

Comments

1

They are very different operations:

  1. lua main.lua: this does
    • reads 3 files,
    • compiles them to bytecode in memory and
    • executes a subset of their bytecode;
  2. 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.

answered Mar 25, 2014 at 2:17

2 Comments

Thank you, and please how can i make one bytecode from 3 other files without lost speed
@lhf Ah yes, because the 2 other reads only occur as part of the execution. Updated.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.