So I tried running the benchmark you sent multiple times in Studio’s command bar with os.clock()
and os_clock()
like your comments suggested. I got values in the range 0.41-0.43 seconds for both of them, which means if there is a difference in performance it seems to be less than the general amount of variance in doing the work (to the human eye).
I also tried putting your benchmark into the Benchmarker plugin, and adjusting the number of iterations (I was able to do 1e2, 1e3, 1e4, and 1e5). Again, I got no clear pattern for which one is better (e.g. for 1e3 what the plugin reports as the fastest version is constantly changing with difference < 1 microsecond).
Benchmark code
--[[
This file is for use by Benchmarker (https://boatbomber.itch.io/benchmarker)
|WARNING| THIS RUNS IN YOUR REAL ENVIRONMENT. |WARNING|
--]]
local os_clock = os.clock
return {
ParameterGenerator = function()
return
end,
BeforeAll = function() end,
AfterAll = function() end,
BeforeEach = function() end,
AfterEach = function() end,
Functions = {
["A"] = function(Profiler)
for i = 1, 1e3 do
os.clock() -- replace the _ in both of these with . for testing
os.clock()
end
end,
["B"] = function(Profiler)
for i = 1, 1e3 do
os_clock() -- replace the _ in both of these with . for testing
os_clock()
end
end,
},
}
The bytecode for the two versions is different, but it appears they have identical performance.
It may be possible that you are getting different results on your machine, but if that is the case you have failed to provide any detailed information that we can work with, such as measurements.
Both the measurements (provided by myself) and the official documentation (provided by @Judgy_Oreo) disagree with you here. We are not being passive-aggressive – we are politely correcting you because you are wrong.
Please read this part of the documentation again:
Luau implements a special optimization called “imports”, where most global chains such as math.max
are resolved when the script is loaded instead of when the script is executed
That is all I will say on this. Good luck on your projects 