So basically after hearing a new alternative for wait() which is task.wait(), I tried out the accuracy between these two.
Legacy wait:
local start = tick()
wait(10)
print("default: "..tostring(tick()-start))
Task wait:
local start = tick()
task.wait(10)
print("task: "..tostring(tick()-start))
However, the results:
Legacy wait:
Task wait:
The legacy wait function is more accurate than task’s wait function even though I ran it multiple times. Why does this happen? Did I read something wrong? Because from what I understand from task.wait() it pauses the thread until the duration is over and the next Heartbeat event is fired. Please help,
task.wait() without any arguments yields for one frame while wait() is inconsistent and yields longer (1/30 sec). I guess wait can be more accurate at the beginning but as more players join and the server gets laggy/exhausted, task.wait will work way better compared to wait which won’t be nearly as accurate as it is at the start.
Also, for benchmarks you shouldn’t use tick, instead, try os.clock which uses CPU ticks and is way more accurate, but in this case as others mentioned both functions return the time yielded so you can just do
local t1 = wait(1)
local t2 = task.wait(1)
print(string.format('\nwait: %f\ntask.wait: %f', t1, t2))