Make your own custom wait function! (FASTER THAN 1/180 of a second!)

Yeah, it doesn’t even matter how fast the computer is: the faster the computer goes the more resources it takes to slow down the fast computer.


@HerculeanYT

Try this code. Making 20 of loops with your function takes the game to 5 FPS. Running 20 loops with task.wait doesn’t even change the milliseconds per frame by 0.01.

local function stupidWait(TIME: number?)
	local t = tick or os.clock
	local i = t()
	TIME = TIME or 0.01
	local w = task.wait
	local r = math.random or Random.new
	while t() - i < TIME do
		if r(1,100000) == 1 then w() end
	end
	return true
end

local runningLoops = 0

game:GetService("UserInputService").InputBegan:Connect(function(inputObject)
	if inputObject.KeyCode == Enum.KeyCode.E and inputObject.UserInputState == Enum.UserInputState.Begin then
		runningLoops += 1
		print("Stupid loops running: "..runningLoops)
		while true do
			stupidWait(1)
		end
	end
end)


local runningLoops = 0

game:GetService("UserInputService").InputBegan:Connect(function(inputObject)
	if inputObject.KeyCode == Enum.KeyCode.Q and inputObject.UserInputState == Enum.UserInputState.Begin then
		runningLoops += 1
		print("Less stupid loops running: "..runningLoops)
		while true do
			task.wait(1)
		end
	end
end)

Your code is over ten thousand times less efficient (not even an exaggeration). No one should ever use this code, and it shouldn’t be on the forums to trick and confuse people.

1 Like

I mean how fast it can process the information, having something faster will just lag or crash it,

true, but even if it has more rescources, its still likely to be effected

1 Like

If the computer is faster won’t it allow the loop to go even faster and use more resources, cause lag?

I’m pretty sure with the Computer itself, not really, but with the Game Client, yes, mainly due to its Engine and Capabilities.

I’ll never grasp why people try to use the same engine features, to make those engine features faster, or finding hacky methods at that, to try to mimick something being “faster”.

On that topic, I feel like even if this thing did what people would expect it too, it would have no purpose at the end of the day. I don’t see any real use case for this in a loop, especially any normal loop. Using task.wait() as is is already pretty fast and superseded the outdated wait() (much needed tbh)

I would just stick with the regular task.wait() method. It’s less code, easier to remember, and saves you time. Also with engine changes, you never know if this will forever be reliable.

Remaking engine features that are already good enough is probably not going to end well, as we can see here. I see that you did it for fun and all, but if that were the case, you probably wouldn’t want to post it here.

Good evening folks.

1 Like

Hello! I am just going to say now that this is not as fast as you claim it is. (Keep in mind the speed is also affected by your processor, and my processor is the i9-13900K, one of the fastest Intel CPUs on the market.)

After conducting some benchmarking I have found that the regular speed of this wait function on my processor is around ~.5249… between ~.6877… (Aproximations, not exact,) on a 0.1 wait. Even standard wait which has been proven to be the slowest built-in wait function currently, is ultimately faster than your custom function.

Original Benchmark:

Now I decided to make an attempt to fix/rewrite your script to be simpler, and at first I tried removing the math.random function in turn for just the w() function. This occasionally made it faster than task.wait, but this was in like every 1 and 10 benchmarks.

After that my friend suggested that I where to clean up the script and make it more simple and refined.

Refined Script:

local function twait(TIME: number?)
local i = tick()
local w = task.wait
while tick() - i < (TIME or 0.01) do
w()
end
return tick() - i
end

Final Benchmark:


This ended up being slightly faster than task.wait(), and blazingly fast compared to wait().

Although Id still use task.wait() over this due to ease, but I hope this helps you, and I hope you learn something from this.

2 Likes