PreciseWait: a small module that beats QuickWait

So I made PreciseWait, a small module but faster than QuickWait and task.wait by miliseconds. If you ever need a precise waiting function (no one does but), feel free to use my module.

Benchmarking

local PreciseWait=require(game.ServerStorage:WaitForChild("PreciseWait"))
local QuickWait=require(game.ServerStorage:WaitForChild("QuickWait"))

local wait=0.001
local tskw=task.wait
local tests=500
local pw=0
local qw=0
local tw=0
task.wait(2)
for i=1,tests,1 do
	pw+=PreciseWait(wait)
	qw+=QuickWait(wait)
	tw+=tskw(wait)
end
pw/=tests
qw/=tests
tw/=tests

warn(`Expected: {wait}`)
warn(`\nPreciseWait: {pw}\nQuickWait: {qw}\ntask.wait: {tw}`)
local small=math.min(pw,qw,tw)
if small==pw then
	warn("PreciseWait wins!")
elseif small==qw then
	warn("QuickWait wins!")
elseif small==tw then
	warn("task.wait wins!")
end

Output:

 Expected: 0.001
 PreciseWait: 0.0002008190001361072
 QuickWait: 0.016491526800031353
 task.wait: 0.016690495199973156
 PreciseWait wins!

Module:
PreciseWait - Creator Store
I’ll leave it here if anyone needs it, this is not going to be updated cuz it’s just a small project

2 Likes

quickwait is no longer used because task.wait exists; a blank task.wait call is supposed to wait one frame and this just waits for a few hundred microseconds

do not use this :warning:

4 Likes

hey, i’m curious, what would be the potential drawbacks of using something like this?

The minimum time you can yield a thread is one frame. Any lower times have to be achieved by crashing the application for a short duration by running some sort of infinite loop. You should never do this.

oh alright, that makes sense then, thanks for the info.

Roblox scripter discovers what a busy loop is