Skip to content

Instantly share code, notes, and snippets.

@stravant
Created August 15, 2021 20:32
Show Gist options
  • Save stravant/47a6ac74995b199ed88790a6e9877240 to your computer and use it in GitHub Desktop.
Save stravant/47a6ac74995b199ed88790a6e9877240 to your computer and use it in GitHub Desktop.
Comparison of dict vs array vector performance in Roblox Lua
local ArrayVector1 = {1, 2, 3, 4}
local ArrayVector2 = {1, 2, 3, 4}
local ArrayVector3 = {1, 2, 3, 4}
local ArrayVector4 = {1, 2, 3, 4}
local DictVector1 = {x = 1, y = 2, z = 3, w = 4}
local DictVector2 = {x = 1, y = 2, z = 3, w = 4}
local DictVector3 = {x = 1, y = 2, z = 3, w = 4}
local DictVector4 = {x = 1, y = 2, z = 3, w = 4}
return {
ParameterGenerator = function()
return
end;
Functions = {
["ArrayVector"] = function(Profiler)
local arrayVector1 = ArrayVector1
local arrayVector2 = ArrayVector2
local arrayVector3 = ArrayVector3
local arrayVector4 = ArrayVector4
for i = 1, 10000 do
local a = arrayVector1[1] + arrayVector1[2] + arrayVector1[3] + arrayVector1[4]
local b = arrayVector2[1] + arrayVector2[2] + arrayVector2[3] + arrayVector2[4]
local c = arrayVector3[1] + arrayVector3[2] + arrayVector3[3] + arrayVector3[4]
local d = arrayVector4[1] + arrayVector4[2] + arrayVector4[3] + arrayVector4[4]
end
end;
["DictVector"] = function(Profiler)
local dictVector1 = DictVector1
local dictVector2 = DictVector2
local dictVector3 = DictVector3
local dictVector4 = DictVector4
for i = 1, 10000 do
local a = dictVector1.x + dictVector1.y + dictVector1.z + dictVector1.w
local b = dictVector2.x + dictVector2.y + dictVector2.z + dictVector2.w
local c = dictVector3.x + dictVector3.y + dictVector3.z + dictVector3.w
local d = dictVector4.x + dictVector4.y + dictVector4.z + dictVector4.w
end
end;
["ArrayVectorTransposed"] = function(Profiler)
local arrayVector1 = ArrayVector1
local arrayVector2 = ArrayVector2
local arrayVector3 = ArrayVector3
local arrayVector4 = ArrayVector4
for i = 1, 10000 do
local a = arrayVector1[1] + arrayVector2[1] + arrayVector3[1] + arrayVector4[1]
local b = arrayVector1[2] + arrayVector2[2] + arrayVector3[2] + arrayVector4[2]
local c = arrayVector1[3] + arrayVector2[3] + arrayVector3[3] + arrayVector4[3]
local d = arrayVector1[4] + arrayVector2[4] + arrayVector3[4] + arrayVector4[4]
end
end;
["DictVectorTransposed"] = function(Profiler)
local dictVector1 = DictVector1
local dictVector2 = DictVector2
local dictVector3 = DictVector3
local dictVector4 = DictVector4
for i = 1, 10000 do
local a = dictVector1.x + dictVector2.x + dictVector3.x + dictVector4.x
local b = dictVector1.y + dictVector2.y + dictVector3.y + dictVector4.y
local c = dictVector1.z + dictVector2.z + dictVector3.z + dictVector4.z
local d = dictVector1.w + dictVector2.w + dictVector3.w + dictVector4.w
end
end;
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment