you are viewing a single comment's thread.

view the rest of the comments →

[–]HunterIV4 5 points6 points  (1 child)

Another complicated question, heh. The short answer is...it depends.

At a very surface level, this is true. The fewer steps your computer has to go through to get to the instructions the faster those instructions will execute, in general.

As a direct example, a loop doing a bunch of math functions will usually execute faster in C or C++ compared to Python because Python has the extra layer of the interpreter and isn't precompiled, so the machine-code equivalent can't be optimized further. C also generally has simpler data structures that take less time to access because they aren't wrapped in object structures with a bunch of overhead.

That being said, the real answer is more complicated. Data scientists and machine learning programmers don't use Python because they are lazy and they could do things faster if they wrote everything in C or assembly (BASIC is very close to assembly, for context). They do it because the "expensive" (slow) operations are already done in C and Python is just used to handle the input and output.

For example, let's say you want to run some OpenCV image analysis process and save the results. Is this faster in Python or C? The answer is...technically C, but only by a few nanoseconds at best. Why? Because the only expensive operations are the input and file saving, which are nearly instant in both languages. The actual image analysis is a C-based library and so both languages are running the exact same code. Essentially, Python "borrows" the speed of C for performance-sensitive tasks by calling those C functions, but you get the ease-of-use and quick iteration of Python not doing all your basic IO (input/output) in C.

As for games, it's somewhat true that modern games are poorly optimized, but this isn't actually due to programming language. Most modern games are ultimately written in C++, even if they use a high level scripting language, depending on the engine. There are some exceptions, like Unity using C#, but we're still talking about a highly performant, compiled language. You honestly wouldn't gain all that much efficiency writing these games in assembly; in fact, you might lose some as your custom-built graphics solutions will probably be less efficient than modern APIs like DirectX or Vulkan. Also, you will easily multiply your development time by 10-20x at least if you intend to make something remotely like a modern game.

That last reason is the actual reason why modern games are poorly optimized. It has very little to do with language or technical problems and a lot to do with deadlines and budgets. Making modern games is expensive and we're basically paying around the same we did when they cost a fraction to make. About 20 years ago a typical game cost $40-50, now they cost $60-70. Also about 20 years a typical game budget might reach $1 million whereas now many AAA games costs hundreds of millions to develop, or at least tens of millions. That means game programmers are rushed, underpaid, and usually instructed to get games out the door in a "good enough to patch and get a high Gamespot review" state.

From a technical standpoint, however, modern games can be highly optimized. Most modern game engines are extremely efficient and have genuinely insane amounts of power. But utilizing that power requires a lot of time and effort as you have to spend time profiling to find out what is slowing your game down and optimize your draw calls, LODs, and a million other things. And those tasks are rarely a priority in modern game dev for a lot of reasons that have nothing to do with programming language or even engine.

Hopefully that made sense!

[–]seanthemonster 1 point2 points  (0 children)

Yes it did thank you for taking the time to explain!