Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

If a script with 2000 lines was all put onto 1 line, would it run more efficiently?

Asked by
traigla 75
8 years ago

So let me show a small example, if a code like this:

while true do
    print("hi")
    print("1")
    print("2")
    print("3")
    print("4")
    print("5")
    wait()
end

was put into a script like this:

while true do print("hi") print("1") print("2") print("3") print("4") print("5") wait() end

would it run more efficiently or make no change at all?

3 answers

Log in to vote
4
Answered by
Wutras 294 Moderation Voter
8 years ago

No, there would be no change at all. The space/enter signs are just to seperate variables and give you a better view over the script. There would be no visible change, not even in a script with 2000 lines. You may use coroutines to make the script faster though. http://wiki.roblox.com/index.php?title=Function_dump/Coroutine_manipulation

Ad
Log in to vote
4
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
8 years ago

No.

Programs must be written for people to read, and only incidentally for machines to execute - Abelson & Sussman

The representation of Lua as code that you write is for humans.

The first step the computer does in executing a script is scan the whole thing once, and turn it into bytecode which is extremely dense and computer readable. The first step, called lexing, breaks your code into words and eliminates space.

So there's absolutely not different in the output between the two.

Write your code for humans. Don't worry about "microoptimizations" like this. A) if they were real, the computer would probably do it for you. B) you're going to get more by making your code do less rather than do the same faster. Optimization comes from eliminating chunks of code, not tweaking names or other tiny things.

Log in to vote
1
Answered by 8 years ago

This wouldn't change at all! Although it would be easier to understand/read. If you did it in multiple lines. But that's my opinion :3.

Answer this question