Vector2 creation so slow compared to Vector3

I am running this bellow script and i get weird timers and i do not understand why.
Vector2 seems so slow compared to Vector3 when i think it should be faster.

local times = 10000000
--------------------------------------------------------- Vector2 Creation
local t = os.clock()
for i = 0, times do
	local shipVec = Vector2.new(i,i)
end
local ft = os.clock()
print("Vector2 Creation", ft - t)
--------------------------------------------------------- Vector3 Creation
local t = os.clock()
for i = 0, times do
	local shipVec = Vector3.new(i,i,i)
end
local ft = os.clock()
print("Vector3 Creation", ft - t)

Results:

Vector2 Creation 0.479585999622941
Vector3 Creation 0.08559640031307936

Is there something i am missing or it is only about internal optimization inside roblox code?

1 Like

This is because Vector3 was optimized, while Vector2 wasn’t. Probably due to it not being used as much.
Note that despite the thread having “Beta” in it, this is already enabled.

2 Likes

So i should see it as Vector3 being way faster and not as Vector2 being slower … this is funny
( i hope Vector2 will be optimized too soon as it should be even faster the Vector3 optimized)

1 Like