Sign in to follow this  
Zaku

python's slowness?

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Quote:
Original post by Zahlman
Did you make something yet?

Was it too slow?

QFT. Until you've actually made something and found it isn't fast enough you shouldn't really worry about it; Python should be plenty fast enough to make some simpler games while you're learning, and by the point you get to something more complicated you'll have learned enough to be able to do what's needed to speed it up.

Share this post


Link to post
Share on other sites
as most of the posters above have allready said, python is generally fast enough,
and when it comes to development time python is very fast, thus you'll complete the project in less time, or get more time to optimize your algoritms (and those are what really matters most of the time).

given an infinite amount of development time and infinite knowledge about your hardware platform assembly languages would give the best results, however as far as i know no person or company has an infinite amount of time and knowledge.

Use python to make the game you want, if some piece of code takes too long to run you can try to optimize the algoritm, if you need even more speed after that you can consider implementing that algoritm as a native function. (using for example C or C++).

most commonly used functions and algoritms are allready implemented though,
ScientificPython for example has native implementations of vectors, linear interpolation, quaternions, and alot of other calculation heavy things.

pygame has native functions (through SDL) for graphics etc.

a simple google search should help you find other native modules you might want if you need to improve performance in some area.

Share this post


Link to post
Share on other sites
Quote:
Original post by drakostar
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.


Your right, I'm not saying that python is a bad thing to make a game with, but based on the performance of Minions of Mirth, I would never use it for a project, but thats just me.
I've heard so many negative reviews about that game its ridiculous. Even its gamespot site has some really negative feedback. Some people complain that half the time they cant even get it running.

But like I said, I'm all for python. All I'm implying is dont expect AAA results from it. In my opinion, if you want something thats potentially golden, go with C/C++ and endure some pain.

My 2 cents.

Share this post


Link to post
Share on other sites
Quote:
Original post by blaze02
You can expect a 10% overhead to most pieces of code. But this heavily depends on what type of code.


It'll be way more than that. I can't say specifically because it really does depend on the specific task being performed. However, I am not concerned with the speed of python. With the ctypes module (built-in as of 2.5 I think...) it's extraordinarily easy to build a C (or C++) library and use it from python.

Share this post


Link to post
Share on other sites
Quote:
Original post by double O seven
But like I said, I'm all for python. All I'm implying is dont expect AAA results from it. In my opinion, if you want something thats potentially golden, go with C/C++ and endure some pain.


Some AAA games which use python (feel free to add to this list):
Disney's Toontown Online
EVE Online
Battlefield 2
Civilization IV

Share this post


Link to post
Share on other sites
Quote:
Original post by double O seven
Your right, I'm not saying that python is a bad thing to make a game with, but based on the performance of Minions of Mirth, I would never use it for a project, but thats just me.
I've heard so many negative reviews about that game its ridiculous. Even its gamespot site has some really negative feedback. Some people complain that half the time they cant even get it running.

But like I said, I'm all for python. All I'm implying is dont expect AAA results from it. In my opinion, if you want something thats potentially golden, go with C/C++ and endure some pain.

You're talking utter nonsense. You seem to have made the jump from "a game written in Python runs poorly" to "Python is bad for games" without the slightest shred of evidence. Did you fail basic logic? I can name more than a few games written with C++ and DirectX that run like crap. Should I assume that this is because they were written with C++/DirectX, despite mountains of evidence to the contrary? And since when is Civ4 not a AAA title?

Share this post


Link to post
Share on other sites
http://shootout.alioth.debian.org/
Is an attempt to objectively evaluate the execution speed, program size, memory usage and other stuff for the most popular languages (or more precisely, compilers). You will see Python perform quite poorly in terms of speed, but check out the lines of code you will need (hint, much fewer than most other languages).

Share this post


Link to post
Share on other sites
Quote:
Original post by drakostar
Quote:
Original post by double O seven
Your right, I'm not saying that python is a bad thing to make a game with, but based on the performance of Minions of Mirth, I would never use it for a project, but thats just me.
I've heard so many negative reviews about that game its ridiculous. Even its gamespot site has some really negative feedback. Some people complain that half the time they cant even get it running.

But like I said, I'm all for python. All I'm implying is dont expect AAA results from it. In my opinion, if you want something thats potentially golden, go with C/C++ and endure some pain.

You're talking utter nonsense. You seem to have made the jump from "a game written in Python runs poorly" to "Python is bad for games" without the slightest shred of evidence. Did you fail basic logic? I can name more than a few games written with C++ and DirectX that run like crap. Should I assume that this is because they were written with C++/DirectX, despite mountains of evidence to the contrary? And since when is Civ4 not a AAA title?


Yeah, ya'll are right, I was wrong. I apologize if that crap sounded misleading. Forgive me. Come to think of it, a lot of colleges and technical institutes start people from higher level languages like python and stuff like that so the students can grasp a better understanding of programming. To the original poster, keep practicing with python bro, your doing right. I should probably start with python too since I said all that crap out of pride.

Share this post


Link to post
Share on other sites
EVE-Online is an MMORPG developed in stackless Python (with critical areas of the client and server running in C++, while virtually everything else is Python).

Share this post


Link to post
Share on other sites
Quote:
Original post by barkholt
http://shootout.alioth.debian.org/
Is an attempt to objectively evaluate the execution speed, program size, memory usage and other stuff for the most popular languages (or more precisely, compilers). You will see Python perform quite poorly in terms of speed, but check out the lines of code you will need (hint, much fewer than most other languages).


However, it's worth bearing in mind that it does not test heavy multimedia performance, which in Python would largely be done by calling out to external libraries, most of which run at compiled C++ speed. If anything, Python is therefore more suitable for games than it is for its more typical tasks.

Share this post


Link to post
Share on other sites
Python *is* slower than C++, noone denies that. But 90% of the time, it doesn't matter as much as the fact that it makes you more productive. Now, what about the other 10%? You can use an external library, like Numeric, Panda3D, PyOgre and a ton others. You can write an external module in C++ with Boost::Python. You can write it with Pyrex(a Python-like language with C types). You can use Psycho which significantly boosts many cases of algorithmic Python code. You can consider to use Shedskin, a Python-To-C++ compiler that takes pure but implictly statically typed Python modules(I've tried it myself, and it's pretty fast, nearly as fast as an equivalent C++ program actually, although ShedSkin is still in experimental phase). In all of those cases the classes and functions exposed behave exactly the same as if they were created in Python, and that's the important thing.

In short, don't worry about it. Focus on writing your game in Python, since that's the language you've chosen, the best way you can, without compromising clarity for "speed". When you profile and determine the critical parts of your code, there is the plethora of options I mentioned.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this