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

?Why is the script performance for a less efficient script better than the more efficient one

Asked by 4 years ago
Edited 4 years ago

Efficient script Has about 2 to 4% performance

local tbl = {workspace.Part,workspace.Part1,workspace.Part2,workspace.Part3}


while wait() do
    for i,v in pairs(tbl) do
        v.Position = v.Position + Vector3.new(0,.01,0)
    end
end


Unefficient script

Has about .3 to .5 performance

local Part = game.Workspace.Part
local Part1 = game.Workspace.Part1
local Part2 = game.Workspace.Part2
local Part3 = workspace.Part3






while wait() do
    Part.Position = Part.Position +Vector3.new(0,.01,0)
    Part1.Position = Part1.Position +Vector3.new(0,.01,0)
    Part2.Position = Part2.Position +Vector3.new(0,.01,0)
    Part3.Position = Part3.Position +Vector3.new(0,.01,0)
end

From the performance statistics the Unefficient script is less laggier by almost 8x

1
The first script is calling multiple functions. The for-loop iterator is called every loop including the instantiation pairs(tbl). pidgey 548 — 4y
0
This was made by CntKillMe, it should help if you want to understand https://docs.google.com/document/d/1KlrlNYNfVKyvTbmJBoVODOqMJF-wTn_JbGUEm0G6RIM/edit pidgey 548 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

not exacly sure what you mean but in the first script you are using a table to make changes to several items at once, it makes the changes like they are one thing. in the second script you dont use a table so the script have to change the position on them one by one and that takes a bit longer since they dont work as one part, atleast thats how i believe it works

1
Wrong. The first script iterates through the table in a loop. Loops are procedural and nothing is happening 'at once'. Each script changes each part one by one. pidgey 548 — 4y
Ad

Answer this question