defold
defold copied to clipboard
Wrong os.clock() result for MacOS m1
os.clock() return seconds with wrong scale
To Reproduce (REQUIRED)
- create script
function update()
print(os.clock());
end
- run3.
Expected behavior (REQUIRED) Return time in seconds
Defold version (REQUIRED):
- Version 1.3.0 and 1.2.192
Platforms (REQUIRED):
- Platforms: MacOS m1 editor
https://www.youtube.com/watch?v=rc7QtML3-Mw
Is this really specific to the M1? It seems like clock() produces a different value on macOS compared to Windows and Linux.
https://stackoverflow.com/questions/16697005/clock-and-clocks-per-sec-on-osx-10-7
Or could it be that CLOCKS_PER_SEC is wrong on M1?
Two questions:
- Does it work correctly on an M1 using Lua 5.4?
- How does it compare to
socket.gettime()
Running this with Lua 5.4 from a terminal actually yield the correct results:
for i=1,100 do
print(os.clock())
local t = os.time()
while os.time() == t do
end
end
I see a new number every second or so.
Or simplifed:
for i=1,100 do
local c = os.clock()
print(c)
local t = math.floor(c)
while math.floor(os.clock()) == t do
end
end
for first code 1 have this output:
for i=1,20 do
print(os.clock())
local t = os.time()
while os.time() == t do
end
end
DEBUG:SCRIPT: 0.167582
DEBUG:SCRIPT: 0.386283
DEBUG:SCRIPT: 1.399068
DEBUG:SCRIPT: 2.406746
DEBUG:SCRIPT: 3.419945
DEBUG:SCRIPT: 4.440478
DEBUG:SCRIPT: 5.460063
DEBUG:SCRIPT: 6.472191
DEBUG:SCRIPT: 7.485179
DEBUG:SCRIPT: 8.49776
DEBUG:SCRIPT: 9.516492
DEBUG:SCRIPT: 10.535626
DEBUG:SCRIPT: 11.548969
DEBUG:SCRIPT: 12.561566
DEBUG:SCRIPT: 13.574475
DEBUG:SCRIPT: 14.59381
DEBUG:SCRIPT: 15.611856
DEBUG:SCRIPT: 16.624258
DEBUG:SCRIPT: 17.636988
DEBUG:SCRIPT: 18.649969
When i run
function init(self)
self.t = 0;
end
function update(self, dt)
self.t = self.t + dt;
print(os.clock(), self.t)
end
I have
DEBUG:SCRIPT: 0.171484 0.033333335071802
DEBUG:SCRIPT: 0.173843 0.050000002607703
DEBUG:SCRIPT: 0.176924 0.066666670143604
DEBUG:SCRIPT: 0.179228 0.083333337679505
DEBUG:SCRIPT: 0.181357 0.10000000521541
DEBUG:SCRIPT: 0.183559 0.11666667275131
DEBUG:SCRIPT: 0.185966 0.13333334028721
DEBUG:SCRIPT: 0.188358 0.15000000782311
DEBUG:SCRIPT: 0.191031 0.16666667535901
DEBUG:SCRIPT: 0.193158 0.18333334289491
DEBUG:SCRIPT: 0.195606 0.20000001043081
DEBUG:SCRIPT: 0.198345 0.21666667796671
DEBUG:SCRIPT: 0.201115 0.23333334550261
DEBUG:SCRIPT: 0.203612 0.25000001303852
DEBUG:SCRIPT: 0.209906 0.26666668057442
DEBUG:SCRIPT: 0.21243 0.28333334811032
DEBUG:SCRIPT: 0.214832 0.30000001564622
DEBUG:SCRIPT: 0.217598 0.31666668318212
DEBUG:SCRIPT: 0.220295 0.33333335071802
DEBUG:SCRIPT: 0.22328 0.35000001825392
DEBUG:SCRIPT: 0.226013 0.36666668578982
DEBUG:SCRIPT: 0.228445 0.38333335332572
DEBUG:SCRIPT: 0.231316 0.40000002086163
DEBUG:SCRIPT: 0.234052 0.41666668839753
DEBUG:SCRIPT: 0.236349 0.43333335593343
DEBUG:SCRIPT: 0.238104 0.45000002346933
DEBUG:SCRIPT: 0.240087 0.46666669100523
DEBUG:SCRIPT: 0.242559 0.48333335854113
DEBUG:SCRIPT: 0.244147 0.50000002607703
DEBUG:SCRIPT: 0.245737 0.51666669361293
DEBUG:SCRIPT: 0.247588 0.53333336114883
DEBUG:SCRIPT: 0.24942 0.55000002868474
DEBUG:SCRIPT: 0.251238 0.56666669622064
DEBUG:SCRIPT: 0.253747 0.58333336375654
DEBUG:SCRIPT: 0.255287 0.60000003129244
DEBUG:SCRIPT: 0.257157 0.61666669882834
DEBUG:SCRIPT: 0.259654 0.63333336636424
DEBUG:SCRIPT: 0.262372 0.65000003390014
DEBUG:SCRIPT: 0.265063 0.66666670143604
DEBUG:SCRIPT: 0.267607 0.68333336897194
DEBUG:SCRIPT: 0.270232 0.70000003650784
DEBUG:SCRIPT: 0.272732 0.71666670404375
DEBUG:SCRIPT: 0.275057 0.73333337157965
DEBUG:SCRIPT: 0.277403 0.75000003911555
DEBUG:SCRIPT: 0.279531 0.76666670665145
DEBUG:SCRIPT: 0.281844 0.78333337418735
DEBUG:SCRIPT: 0.283397 0.80000004172325
DEBUG:SCRIPT: 0.285105 0.81666670925915
DEBUG:SCRIPT: 0.286929 0.83333337679505
DEBUG:SCRIPT: 0.288634 0.85000004433095
DEBUG:SCRIPT: 0.290572 0.86666671186686
DEBUG:SCRIPT: 0.292375 0.88333337940276
DEBUG:SCRIPT: 0.294216 0.90000004693866
DEBUG:SCRIPT: 0.29615 0.91666671447456
DEBUG:SCRIPT: 0.29871 0.93333338201046
DEBUG:SCRIPT: 0.301453 0.95000004954636
DEBUG:SCRIPT: 0.303729 0.96666671708226
DEBUG:SCRIPT: 0.306071 0.98333338461816
DEBUG:SCRIPT: 0.308367 1.0000000521541
I not sure this is M1 specific bug. I have two m1 MacBook and one PC. On PC its work good
If I run project as HTML5 bundle -- problem not repeated
socket.gettime() work correct
Run on Lua.5.4.4 from homebrew. Looks like all correct
while true do
print(os.clock())
end