Is using math instead of built-in functions faster?

Last week i decided to make chunk generation and chunk loading in roblox, when doing soo i’ve learned few things like pararrel luau that i never used before or about some chunk-loading techniques, but what i wonder about now is if using math i can optimize built-in functions like math library or vector methoods, i’ve heard that if process runs a lot of times or very often it’s reccomended to do it

Soo is using math better than roblox’s functions?

1 Like

i assume so

using math.clamp() is a lot faster and efficient than making a whole function for it

Hmmm, but what about functions like Magnitude, math.pow or math.sqrt? they seem very easy to recreate by using operators

im also pretty sure those ones are more efficient, also ALOT more convenient

I just did a test on my computer (CPU: 10900k)

image

I made a custom magnitude function with proper type declaration to make it as fast as possible. With 100 million tests for each function.

The built in magnitude function seems to be around 50% faster.

1 Like

Probably to make efficient custom function i need to use custom made coordinates and different shapes, still thx for tests and tips

Don’t bother. Vector3s are good enough. What are you trying to do?

1 Like

Overall chunk generation and chunk loading, i’m experimenting with most efficient methoods and stuff to make it good

Using built-in is faster, probably because I think these are C++ functions

1 Like

Then built in objects will be the fastest as these are not run in lua code but rather on a lower level which will minimize memory usage and speed.

Unless a function was HORRIBLY implemented directly by roblox, their built in methods for doing something will always be faster.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.