I need to know how fast LUAU is compared to c++

Well, as the title says, i want to know how slow LUAU is compared to c++ (with only 1 core available).
So i can decide that should i do the fun ray-marching project, or should i forget about it.
I would like to see some linear graph with iterations and the time the iterations have been finished in for both languages (that would help me a lot).

Luau’s compiler and VM runs on C++. There’s you’re answer on what’s faster.

2 Likes

“How fast LUAU is compared to c++”, I didn’t ask is Luau slower than c++, because i know that already.

They cant be compared, one is an interpreted language and the other is compiled.

They’re based on different operation principles where one operates directly on your CPU and the other uses a VM to operate a list of instructions. C++ will always be faster than Luau because of this

2 Likes

Why not just compare them yourself?

It’s a hard question to answer because Luau benchmarks aren’t widely available, and Luau has only been available in Roblox till just very recently, but there is some information that might prove to be useful:

According to an article from 2016 (this is with Lua 5.3) vanilla Lua performs ~100x slower than C, which is roughly comparable to C++ in many high performance use cases, while LuaJIT performed roughly 3x slower with the same task. A closer inspection of the article showed that a specific valuable LuaJIT feature seems to have been accidentally ignored though, so presumably the LuaJIT implementation wasn’t as fast as it could have been.

That’s just the introductory test though, and the test case in question seems to be solving for approximations of differential equations. Ray tracing typically involves a lot more structure crawling than pure math so this test would be less representative there, but since you mentioned you wanna do ray marching instead I’d guess it’d be much closer as ray marching is more math heavy, without knowledge of what exactly it is you are aiming for.

To bridge the gap with that comparison I also found another post on this forum that references an externally stated claim that Luau is generally somewhere between vanilla Lua and LuaJIT performance. The claim states that Luau approaches LuaJIT performance for specific application and lists a few performance benchmarks, but it doesn’t appear to list the same benchmark, at least not in the bigger performance gap part of the graph.

The post in question & some links from it:

https://devforum.roblox.com/t/luau-speed-os-emulation/1285611/17

luau-lang.org

I’d highly recommend finding a performance benchmark script you can use to test Luau vs LuaJIT, and a similar C++ program you can use to benchmark numbers against each other.

LuaJIT seems like a possibly viable alternative for your use case if you’re adamant on using a Lua variation, but you would lose out on the additional abstractions that Luau provides.

For C++ you can generally avoid some of the more nasty or hard to learn/use features for a use case like ray marching, but it still does help to understand C++'s underlying memory model to write performant code. I don’t know what your experience level is with C++ and how much of this you already know, but with C++ it can be pretty easy to accidentally shoot yourself in the foot and introduce major bottlenecks that can slow down a program by orders of magnitude. It’s all too easy to allocate more memory than necessary and more often than necessary, or use abstraction patterns that have way more performance overhead for very little organizational benefit for the use case at hand when following advice from articles and help threads on the internet.

On the flip side it can also be a lot easier to make savings in those areas because you don’t have to fight forced abstractions that higher level languages like Lua provide for ease of use.

2 Likes

image
Guess what i am going to render with this formula :smiley: Z^2+C
I’m going to add ambience (I made up this formula by myself AverageOfAllDistances/Max(AllDistances) (possible return: 0 to 1) it will give us idea about the surroundings) and coloring too(Will be Z-C distance based, but i’m not sure how the array of colors should looks like tho). I could speed up the process, but i’m not sure about this by removing iterations from the params and just turn it into a global could change anything on this scale (I assume it will take less bytes, because my function will take as expected less arguments).
If the simulation will run fast, i might add camera controls because it’s possible to do.

1 Like

Roblox provides some benchmarks that you can use here

1 Like