python's slowness?

Started by
20 comments, last by mikeman 17 years, 6 months ago
ive heard that pythons a bit slow compared to the other languages, like java or c++, but i want some sort of comparison as to how slow it really is compared to c++. Is there any ways to bypass the slowness? cause i really would rather use python for games.
Advertisement
Don't worry about Python's performance. The idea is that you develop your game in Python, then profile your code and replace the slow pieces with C/C++ (or better yet, Pyrex). You'll get stuff done much quicker, and you'll avoid the trap of constantly worrying about performance.

- Mike
Programs written in Python will typically be slower than programs written in C++ or Java. However:


  • it doesn't matter with many programs (think "events": the program is idle while waiting for something, and C++ doesn't make waiting faster),

  • a lot of programs are I/O bound,

  • Python has numerous modules written in other languages when speed really is important (like the Numeric module). Most of your speed-critical logic will happen in these.



If you want to bypass the "slowness", write a module in C, C++, FORTRAN, ... and use it from Python. The idea is to profile your program and eventually recode the bottlenecks in another language.

This being said, languages are tools, and some tools just aren't good at solving some problems: you won't write a TCP/IP stack in Python (not a practical one anyway).

Finally, you said that you'd rather use Python for games. Unless you're working on some AAA title or targeting a tiny embedded system, why worry so much about performances? Do something you enjoy, and you might actually finish it. [smile]
hmm, you're right. but when using a module, for example c++, so i have to learn c++?
Quote:Original post by Zaku
hmm, you're right. but when using a module, for example c++, so i have to learn c++?


When using it, absolutely not. To you, it's just plain Python. [smile]
Did you make something yet?

Was it too slow?
Until you personally have found Python's performance to be a barrier in the development of your games, then you shouldn't be worrying about it.

Should you really care if Biased Person A says Language X is slow? If you are learning to program and enjoying using Python, then what does it matter if C++, Java or any other language comes out marginally faster in some test on some obscure feature or algorithm you won't ever need [smile]

Just get on with making games! ...that's an order [wink]
Richard 'ViLiO' Thomasv.net | Twitter | YouTube
Keep in mind that when I say this, I'm not attempting to degrade the company, the game, or the python programming language. But you wanna see how slow python is when its used to make a game? Go to the prairie games site and download the demo for a game called Minions of Mirth. That game employ's python for gameplay.

http://www.prairiegames.com/

And heres the outline on how they made the game.

http://www.prairiegames.com/phpBB2/viewtopic.php?t=1242&highlight=post+mortem
Quote:Original post by double O seven
Keep in mind that when I say this, I'm not attempting to degrade the company, the game, or the python programming language. But you wanna see how slow python is when its used to make a game? Go to the prairie games site and download the demo for a game called Minions of Mirth. That game employ's python for gameplay.

http://www.prairiegames.com/

And heres the outline on how they made the game.

http://www.prairiegames.com/phpBB2/viewtopic.php?t=1242&highlight=post+mortem

looks like a nice game, for 3d. im not really a 3d fan, more of 2d, but those are pretty good graphics. i underestimated python!
Quote:Original post by double O seven
But you wanna see how slow python is when its used to make a game? Go to the prairie games site and download the demo for a game called Minions of Mirth. That game employ's python for gameplay.

Uh, I could write a text adventure that runs like crap in pure assembly.

I've never heard anyone complain about the performance of PyOgre, and I've seen some pretty impressive stuff done with it. You can also take Civilization 4 for a professional example of using Python in a game.

The bottom line is that if you're doing lots of math, you may want to push it out to C/C++ extensions (esp. Python wrappers around C/C++ libraries). Python is a mature, popular language with many premade wrappers available, and it's not hard to make your own with SWIG or Boost.Python if you need to. Worrying about wasting a couple CPU cycles when you're developing for 2-3GHz processors is...crazy. The algorithms and data structures you use are many orders of magnitude more important than the language.

This topic is closed to new replies.

Advertisement