Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Incredible performace of Lua (luajit) over C++  (Read 25557 times)

0 Members and 1 Guest are viewing this topic.

DarkRoku12

  • Full Member
  • ***
  • Posts: 203
  • Lua coder.
    • View Profile
    • Email
Re: Incredible performace of Lua (luajit) over C++
« Reply #15 on: May 30, 2015, 04:45:44 am »
Well if fraps tells you that you got low fps, it's certainly that there is a problem with your gpu-side work. In particular when you're doing nothing else than display.
Which means it have nothing to do with C++ or lua....

This are not low fps because there are displaying 1000 crates (512x512) each one.

My pc have i7 4th generation and a max CPU frequency of 3 ghz.

With a regular game i get (with no frame limit)  1400-1700.
I would like a spanish/latin community...
Problems building for Android? Look here

Rhimlock

  • Jr. Member
  • **
  • Posts: 73
    • View Profile
Re: Incredible performace of Lua (luajit) over C++
« Reply #16 on: June 01, 2015, 09:40:16 am »
Am I missing something?
Where is the Lua-code?
How should someone be able to compare your implementations, when you just post the C++ code and say "Look, my Lua Game Engine is faster than C++/SFML"?

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: Incredible performace of Lua (luajit) over C++
« Reply #17 on: June 01, 2015, 10:06:08 am »
Am I missing something?
Obviously several posts :P

Where is the Lua code? How do we know it's equivalent?
The problem is, without code your benchmark doesn't really express anything (we don't know exactly what you did and how you did it). Furthermore, it can't be repeated by others. In short, it's no proof.
We really need the source of both test cases in order to reproduce your performance claims.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Rhimlock

  • Jr. Member
  • **
  • Posts: 73
    • View Profile
Re: Incredible performace of Lua (luajit) over C++
« Reply #18 on: June 01, 2015, 10:13:02 am »
Obviously several posts :P

I saw your posts about the source but never saw a reply from DarkRoku where he posted the source.
So I thought maybe i overlooked some detail.

At this point, I could just make a Lua game engine that is slower than his C++ implementation to disprove his hypothesis.  ;D


SLC

  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: Incredible performace of Lua (luajit) over C++
« Reply #19 on: June 02, 2015, 04:57:28 pm »
From what I could gather a while back. LuaJit uses SIMD instructions if allowed (by default) and available on the CPU. But you seem to miss the point. In almost every line of your code, you'll end up calling functions. And sometimes (many times) you'll end up calling functions from C/C++ (hopefully through FFI if you want to keep the speed otherwise it's useless with generic binding). And C/C++ will kill LuaJit when it comes to function calls.

Yes, LuaJit could outperform C/C++ when it comes to number crunching, if you have a really modern CPU and you allowed the use of SIMD instructions (will choose the best available instructions). But I highly doubt your code will be only numeric expressions.

Create two serious applications with a few thousands lines of code and not just a simple generic function. And then run them again. You could also disable SIMD instructions in LuaJit if you really want to have a one on one benchmark.

Not to mention that when you start using FFI in LuaJit to maintain that speed. All your safety goes out the window. You might think that C/C++ is an unsafe language. Just wait until you deal with that.
« Last Edit: June 02, 2015, 05:04:19 pm by SLC »

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Incredible performace of Lua (luajit) over C++
« Reply #20 on: June 04, 2015, 09:08:17 pm »
Yes, LuaJit could outperform C/C++ when it comes to number crunching, if you have a really modern CPU and you allowed the use of SIMD instructions (will choose the best available instructions)
Modern C++ compilers will also take advantage of SIMD instructions as well (if you let them optimize for modern CPUs) and are actually quite aggressive about vectorizing loops and other code constructs.

Some links to add substance to the above:
http://llvm.org/docs/Vectorizers.html
https://gcc.gnu.org/projects/tree-ssa/vectorization.html
https://msdn.microsoft.com/en-us/library/hh872235.aspx

SLC

  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: Incredible performace of Lua (luajit) over C++
« Reply #21 on: June 16, 2015, 03:11:37 am »
Modern C++ compilers will also take advantage of SIMD instructions as well (if you let them optimize for modern CPUs) and are actually quite aggressive about vectorizing loops and other code constructs.

I know that. However, once you've compiled C++ to use SIMD you can't run your program on a CPU that doesn't feature those instructions. With Lua on the other hand, this is decided at runtime and uses it only if the CPU supports that feature. Therefore your LuaJit program can run both on an old CPU and use only the available instructions and on a newer CPU and use newer instructions without having two binaries.

But that wasn't the point of my post. I simply suggested that LuaJit might have optimized the resulted instructions while C++ didn't (probably wasn't allowed). Which means that the result of the benchmark is almost irrelevant.

FRex

  • Hero Member
  • *****
  • Posts: 1845
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Incredible performace of Lua (luajit) over C++
« Reply #22 on: June 16, 2015, 11:11:24 am »
Quote
I know that. However, once you've compiled C++ to use SIMD you can't run your program on a CPU that doesn't feature those instructions.
Good luck finding a worthwhile x86(-64) desktop CPU with no SSE2 that is younger than 5 years old and faster than 2 Ghz. I'm not even sure one like that exists.

Quote
I simply suggested that LuaJit might have optimized the resulted instructions while C++ didn't (probably wasn't allowed).
This is not true, it's actually the other way around: statically typed and compiled languages are allowed to make long running, drastic optimizations that dynamic languages can't.
Back to C++ gamedev with SFML in May 2023

Daid

  • Newbie
  • *
  • Posts: 29
    • View Profile
Re: Incredible performace of Lua (luajit) over C++
« Reply #23 on: July 11, 2015, 01:36:18 pm »
Quote
I know that. However, once you've compiled C++ to use SIMD you can't run your program on a CPU that doesn't feature those instructions.
Good luck finding a worthwhile x86(-64) desktop CPU with no SSE2 that is younger than 5 years old and faster than 2 Ghz. I'm not even sure one like that exists.
Been using SSE2 compile flags on a project for 3 years now. More then 50.000 daily users (and growing) not a single complain ever.



But the post here has little to do with C++ vs LuaJit. As the performance of that code should not be CPU bound. Most likely the C++ version is doing vsync while the LuaJit version is not or something silly like that.
Or, more likely, you say you have the physics engine enabled on the LuaJit version, making crates fall off-screen. Off-screen rendering is quite fast, as the GPU will say "I don't have to do shit, let's skip this".

Hydra

  • Newbie
  • *
  • Posts: 37
    • View Profile
Re: Incredible performace of Lua (luajit) over C++
« Reply #24 on: August 18, 2015, 07:41:11 pm »
I like a lot more C over C++.
Nice, but you're making a C++ comparison here. Personal preferences should not affect an objective and expressive benchmark ;)

3) Its faster ( OpenGL is faster that DirectX ) ( chipmunk-physics are faster than Box2d)
Sorry, but this is complete bullshit, especially with those examples. It's so fundamentally wrong I don't even know where to start. But you'll find these kinds of arguments all over the internet, there's no need to repeat them here... So I'd say we concentrate on the benchmark in this thread, no need for another C vs C++ flamewar.

I will see carefully of RAII , looks ougly but great for the memory leaks.
You should really read my article. Exactly this kind of unfunded myths are refuted.

To be honest, you're just giving me more and more the impression that you don't really know what you're talking about. No offense, but when you're trying to prove something (especially speed), you should be familiar with the programming language and measuring techniques -- or at least willing to incorporate improvement suggestions, rather than sticking to dogmas you've heard somewhere and never questioned.

We're still missing the Lua code, by the way :)

He just uploaded a benchmark of Lua code and C++ code. Seeing as you guys generally help people there's no need to be so rude to him:

"this is complete bullshit!"
"It's so fundamentally wrong I don't even know where to start"
"giving me more and more the impression that you don't really know what you're talking about"
"rather than sticking to dogmas you've heard somewhere and never questioned."

All he's done is uploaded a benchmark of his Lua engine vs SFML C++ engine and you suddenly go all defensive and start being rude to him. Perhap's you shouldn't even reply to comments seeing as when viewing your posts the first one includes a quote of someone saying your being offensive.

Tank

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1486
    • View Profile
    • Blog
    • Email
Re: Incredible performace of Lua (luajit) over C++
« Reply #25 on: August 19, 2015, 10:12:44 am »
Disclaimer, as I also replied and thus feel addressed: I was not being rude! :D I really just wanted to see the Lua code. I even think that it's possible that his tests outperform C++. JIT compilation is quite powerful, as it can optimize in a field where compile-time optimizers have already left the building.

Hydra

  • Newbie
  • *
  • Posts: 37
    • View Profile
Re: Incredible performace of Lua (luajit) over C++
« Reply #26 on: August 19, 2015, 02:54:22 pm »
Disclaimer, as I also replied and thus feel addressed: I was not being rude! :D I really just wanted to see the Lua code. I even think that it's possible that his tests outperform C++. JIT compilation is quite powerful, as it can optimize in a field where compile-time optimizers have already left the building.

I was only mainly talking about Nexus and his first comment which was completely unprovoked and just rude.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: Incredible performace of Lua (luajit) over C++
« Reply #27 on: August 19, 2015, 03:21:00 pm »
You take a 3 months old post out of context, denying any backgrounds leading to it, for... what? If you have a problem with my attitude, write me a PM, there's no need to necromance this thread for an off-topic discussion.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Hydra

  • Newbie
  • *
  • Posts: 37
    • View Profile
Re: Incredible performace of Lua (luajit) over C++
« Reply #28 on: August 19, 2015, 03:59:47 pm »
You take a 3 months old post out of context, denying any backgrounds leading to it, for... what? If you have a problem with my attitude, write me a PM, there's no need to necromance this thread for an off-topic discussion.

I didn't purposely deny the lead up I was just quoting the parts of it that were rude. For people who didn't want to read the whole post which I quoted.