Last active
April 15, 2017 00:59
-
-
Save Validark/0786dcc7d31502e09ae63e85fd0245e7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- paste this into your codebar to convert your old syntax to the new syntax | |
local NevermoreName = "NevermoreEngine" | |
local function AdjustScriptSyntax(Script) | |
if Script:IsA("LuaSourceContainer") then | |
local ScriptSource = Script.Source | |
Script.Source = (ScriptSource:gsub((ScriptSource:match("local ([%a_]%w*) = " .. NevermoreName .. "%.LoadLibrary") or "LoadLibrary") .. "(%b())", function(x) | |
return ("LoadLibrary[%s]"):format(x:sub(2,-2)) | |
end):gsub(NevermoreName .. "%.Get(%w+)(%b())", function(FunctionName, String) | |
return ("%s.%ss[%s]"):format(NevermoreName, FunctionName, String:sub(2,-2)) | |
end)) | |
end | |
end | |
local function CallOnDescendants(Instance, FunctionToCall) | |
--- Calls a function on an object and its children | |
-- Note: Parents are always called before children. | |
FunctionToCall(Instance) | |
local Children = Instance:GetChildren() | |
for a = 1, #Children do | |
CallOnDescendants(Children[a], FunctionToCall) | |
end | |
end | |
local Repository = game:GetService("ServerScriptService"):FindFirstChild("Modules") | |
if Repository then | |
Repository.Parent = game:GetService("ServerStorage") | |
CallOnDescendants(Repository, function(Script) | |
if Script:IsA("Script") then | |
Script.Parent = game:GetService("ServerScriptService") | |
elseif Script.ClassName ~= "Folder" and Script.ClassName ~= "ModuleScript" then | |
Script.Parent = game:GetService("ServerStorage") | |
end | |
end) | |
end | |
local NevermoreEngine = game:GetService("ReplicatedStorage"):FindFirstChild(NevermoreName) | |
if NevermoreEngine then | |
NevermoreEngine.Source = game:GetService("HttpService"):GetAsync("https://raw.githubusercontent.com/NevermoreFramework/Nevermore/master/Engine/Nevermore.module.lua") | |
end | |
for _, Directory in next, { -- These are really the only places where you should have objects, excluding Lighting | |
game:GetService("Workspace"); | |
game:GetService("Players"); | |
game:GetService("Lighting"); | |
game:GetService("ReplicatedFirst"); | |
game:GetService("ReplicatedStorage"); | |
game:GetService("ServerScriptService"); | |
game:GetService("ServerStorage"); | |
game:GetService("StarterGui"); | |
game:GetService("StarterPack"); | |
game:GetService("StarterPlayer"); | |
} do | |
CallOnDescendants(Directory, AdjustScriptSyntax) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- @author Validark | |
--[[ | |
Classifications: | |
devSparkle's version is referred to as "NevermoreEngine" | |
Validark's version is referred to as "Resources" | |
Foreword: | |
These tests were conducted on live server-client models | |
The code used for each was identical aside from Module syntax changes | |
Module arrays list the times it took to load the ModuleScript itself | |
Stuff arrays list the times it took to load one ModuleScript and one RemoteEvent | |
Conclusion: | |
Validark's version is faster at everything except for the portion referred to as Server.Stuff | |
The reason that it is SLIGHTLY slower at Server.Stuff(loading a single ModuleScript and a single RemoteEvent) is because | |
Validark's version generates RemoteEvent functionality upon initial use. Validark's version would prove faster in this regard in subsequent calls | |
for resources of the type RemoteEvent, and should therefore be seen as faster overall | |
Benefits of using Validark's version: | |
As this establishes, it is faster in every way | |
Capable of managing any data type, and is not limited to RemoteEvents and RemoteFunctions as devSparkle's version is | |
The `Resources` table only contains the Folders you ask for, and doesn't impose any functions other than `LoadLibrary` by default | |
More intelligent detection of whether something should be moved a private Server ModuleScript | |
Subsequent calls for the same resource is merely indexing a table, which is much faster than executing a function each time | |
Built better for large codebases | |
Limitations of using Validark's version: | |
You need to switch "()" to "[]" in LoadLibrary calls | |
LoadLibrary("OutfitManager") --> LoadLibrary["OutfitManager"] | |
You need to switch "()" to "[]", remove "^Get", and add "s$" to retrieval statements | |
NevermoreEngine.GetRemoteEvent("SetTeam") --> NevermoreEngine.RemoteEvents["SetTeam"] | |
However, all of the above changes can be made automatically by a script pasted into the codebar | |
(save fist) | |
Paste the codebar.lua script into your codebar and run it, and it will correct your scripts to the new syntax | |
Make sure your "Modules" repository is in "ServerStorage" (it was previously in ServerScriptService) | |
Test it to make sure it didn't break, and if it didn't, everything worked properly! | |
--]] | |
-- Raw data | |
local NevermoreEngineTimes = { | |
Server = { | |
Module = { | |
0.001558780670166; | |
0.001284122467041; | |
0.0015411376953125; | |
0.0021071434020996; | |
0.0023806095123291; | |
0.0016839504241943; | |
}; | |
Stuff = { | |
0.00031113624572754; | |
0.00032973289489746; | |
0.00031113624572754; | |
0.0005180835723877; | |
0.00038719177246094; | |
0.00047039985656738; | |
}; | |
}; | |
Client = { | |
Module = { | |
0.0012357234954834; | |
0.0025279521942139; | |
0.0017778873443604; | |
0.0013446807861328; | |
0.0018188953399658; | |
0.0013728141784668; | |
}; | |
Stuff = { | |
0.00015568733215332; | |
0.00052523612976074; | |
0.00017285346984863; | |
0.00019216537475586; | |
0.00035977363586426; | |
0.00018978118896484; | |
}; | |
} | |
} | |
local ResourcesTimes = { | |
Server = { | |
Module = { | |
0.00091814994812012; | |
0.00148606300354; | |
0.0011639595031738; | |
0.0011396408081055; | |
0.0011963844299316; | |
0.0014677047729492; | |
0.00092148780822754; | |
0.0010144710540771; | |
}; | |
Stuff = { | |
0.00029706954956055; | |
0.0006864070892334; | |
0.00035333633422852; | |
0.00033664703369141; | |
0.00041532516479492; | |
0.00037908554077148; | |
0.00042939186096191; | |
0.00037884712219238; | |
}; | |
}; | |
Client = { | |
Module = { | |
0.0019006729125977; | |
0.00073838233947754; | |
0.00092315673828125; | |
0.00057101249694824; | |
0.00081729888916016; | |
0.0005955696105957; | |
0.00067234039306641; | |
0.00070548057556152; | |
}; | |
Stuff = { | |
0.00015521049499512; | |
0.00014972686767578; | |
0.0001678466796875; | |
0.00012755393981934; | |
0.00049304962158203; | |
0.00019502639770508; | |
0.00018000602722168; | |
0.00016069412231445; | |
}; | |
} | |
} | |
-- Analyzation Functions | |
local function Mean(Array, Sample) | |
local Mean = 0 | |
for a = 1, #Array do | |
Mean = Mean + Array[a] | |
end | |
return Mean / (#Array - (Sample and 1 or 0)) | |
end | |
local function Median(Array) | |
table.sort(Array) | |
local Midpoint = #Array / 2 | |
return Array[Midpoint] or Mean{Array[Midpoint - 0.5], Array[Midpoint + 0.5]} | |
end | |
local function Max(Array) | |
table.sort(Array) | |
return Array[#Array] | |
end | |
local function Min(Array) | |
table.sort(Array) | |
return Array[1] | |
end | |
local StandardDeviation | |
local SampleStandardDeviation | |
for a = 1, 2 do | |
local bool = a == 2 | |
local func = function(Array) | |
local Average = Mean(Array) | |
local Deviations = {} | |
for a = 1, #Array do | |
Deviations[a] = (Array[a] - Average)^2 | |
end | |
return Mean(Deviations, bool) ^ 0.5 | |
end | |
if a == 1 then | |
StandardDeviation = func | |
else | |
SampleStandardDeviation = func | |
end | |
end | |
-- Comparisons | |
local Metrics = {Mean = Mean, Median = Median, Max = Max, Min = Min, SampleStandardDeviation = SampleStandardDeviation} | |
local Winners = { | |
Server = { | |
Module = {}; | |
Stuff = {}; | |
}; | |
Client = { | |
Module = {}; | |
Stuff = {}; | |
}; | |
} | |
for Filtering, Tables in next, NevermoreEngineTimes do | |
for StuffLoaded, Times in next, Tables do | |
local ParallelTimes = ResourcesTimes[Filtering][StuffLoaded] | |
for Name, func in next, Metrics do | |
--print() | |
local a, b = func(Times), func(ParallelTimes) | |
--print(Filtering, StuffLoaded, Name, "\nNevermore", a, "\nResources", b) | |
-- Cache which one won | |
Winners[Filtering][StuffLoaded][Name] = a > b and "Resources" or "NevermoreEngine" | |
end | |
end | |
end | |
--[[ | |
Client Module Min | |
Nevermore 0.0012357234954834 | |
Resources 0.00057101249694824 | |
Client Module Mean | |
Nevermore 0.0016796588897705 | |
Resources 0.00086548924446106 | |
Client Module Median | |
Nevermore 0.0013728141784668 | |
Resources 0.00070548057556152 | |
Client Module SampleStandardDeviation | |
Nevermore 0.00048001662258514 | |
Resources 0.00043357181951596 | |
Client Module Max | |
Nevermore 0.0025279521942139 | |
Resources 0.0019006729125977 | |
Client Stuff Min | |
Nevermore 0.00015568733215332 | |
Resources 0.00012755393981934 | |
Client Stuff Mean | |
Nevermore 0.00026591618855794 | |
Resources 0.00020363926887512 | |
Client Stuff Median | |
Nevermore 0.00018978118896484 | |
Resources 0.00016069412231445 | |
Client Stuff SampleStandardDeviation | |
Nevermore 0.00014703934399856 | |
Resources 0.00011865756818243 | |
Client Stuff Max | |
Nevermore 0.00052523612976074 | |
Resources 0.00049304962158203 | |
Server Module Min | |
Nevermore 0.001284122467041 | |
Resources 0.00091814994812012 | |
Server Module Mean | |
Nevermore 0.0017592906951904 | |
Resources 0.0011634826660156 | |
Server Module Median | |
Nevermore 0.001558780670166 | |
Resources 0.0011396408081055 | |
Server Module SampleStandardDeviation | |
Nevermore 0.00040652049916385 | |
Resources 0.00022013452584853 | |
Server Module Max | |
Nevermore 0.0023806095123291 | |
Resources 0.00148606300354 | |
Server Stuff Min | |
Nevermore 0.00031113624572754 | |
Resources 0.00029706954956055 | |
Server Stuff Mean | |
Nevermore 0.00038794676462809 | |
Resources 0.00040951371192932 | |
Server Stuff Median | |
Nevermore 0.00032973289489746 | |
Resources 0.00037884712219238 | |
Server Stuff SampleStandardDeviation | |
Nevermore 8.8230649293702e-005 | |
Resources 0.00011956726124291 | |
Server Stuff Max | |
Nevermore 0.0005180835723877 | |
Resources 0.0006864070892334 | |
Winners = { | |
Server = { | |
Module = { | |
Min = "Resources"; | |
Mean = "Resources"; | |
Median = "Resources"; | |
SampleStandardDeviation = "Resources"; | |
Max = "Resources"; | |
}; | |
Stuff = { | |
Min = "Resources"; | |
Mean = "NevermoreEngine"; | |
Median = "NevermoreEngine"; | |
SampleStandardDeviation = "NevermoreEngine"; | |
Max = "NevermoreEngine"; | |
}; | |
}; | |
Client = { | |
Module = { | |
Min = "Resources"; | |
Mean = "Resources"; | |
Median = "Resources"; | |
SampleStandardDeviation = "Resources"; | |
Max = "Resources"; | |
}; | |
Stuff = { | |
Min = "Resources"; | |
Mean = "Resources"; | |
Median = "Resources"; | |
SampleStandardDeviation = "Resources"; | |
Max = "Resources"; | |
}; | |
} | |
} | |
]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment