I want to know weather a read operation performed on a frozen SharedTable is faster than the same read operation performed on a standard, non frozen SharedTable or not?
I tried to benchmark the read times, but with these results, I do not know whether the difference is simply that small or if there is no actual difference and what I’m seeing as difference is simply just noise.
--!optimize 2
-- Create 2 Identical SharedTables With One Array And One Hash Part, One Frozen, one not Frozen.
local Warmth_Shared_Table: SharedTable = SharedTable.new({[1] = 1, Hi = "Hi"})
local Frozen_Shared_Table: SharedTable = SharedTable.cloneAndFreeze(Warmth_Shared_Table)
local Time: number = 0 -- TValue To Handle Time
local Iterations: number = 1e7 -- Benchmarking Sample Size
local Value: number? | string? = nil -- TValue To Store Results In
-- Cache os.clock So That Calling Clock Just Loads A Register Instead Of A GETIMPORT or a GETUPVAL +
-- GETTABLEKS instructions, Reducing Chances Of Error.
local Clock: typeof(os.clock) = os.clock
task.wait(30) -- Wait For CoreScripts To Setup.
Time = Clock()
for Key: number = 1, Iterations do Value = Warmth_Shared_Table[1] end
Time = Clock() - Time
print(`Warmth Number: {Time / Iterations}`)
Time = Clock()
for Key: number = 1, Iterations do Value = Frozen_Shared_Table[1] end
Time = Clock() - Time
print(`Frozen Number: {Time / Iterations}`)
Time = Clock()
for Key: number = 1, Iterations do Value = Warmth_Shared_Table.Hi end
Time = Clock() - Time
print(`Warmth String: {Time / Iterations}`)
Time = Clock()
for Key: number = 1, Iterations do Value = Frozen_Shared_Table.Hi end
Time = Clock() - Time
print(`Frozen String: {Time / Iterations}`)
Result:
11:15:14.354 Warmth Number: 1.4017838000145274e-07 - Server - Script:20
11:15:15.717 Frozen Number: 1.3632349999970757e-07 - Studio
11:15:17.379 Warmth String: 1.6611362000112422e-07 - Studio
11:15:18.980 Frozen String: 1.6006959999795072e-07 - Server - Script:35
Now I do not know if this 4 - 6 nanosecond difference is the difference in read speeds or just due to noise
If anyone knows about it, please let me know! Thanks!
