简体   繁体   中英

How much slower is a wxWidget written in Python versus C++?

I'm looking into writing a wxWidget that displays a graphical node network, and therefore does a lot of drawing operations. I know that using Python to do it is going to be slower, but I'd rather get it working and port it later when its functional. Ideally, if the performance hit isn't too great, I'd prefer to keep the codebase in Python for easy updates.

What I'm wondering is how much slower should I expect things to go? I realize this is vague and open ended, but I just need a sense of what to expect. Will drawing 500 circles bog down? Will it be noticeable at all? What are your experiences?

IMHO, main bottleneck will be the data structures you are going to use for representing the network graph. I have coded a similar application for tracing dependencies between various component versions in a system and graphics was the last thing I had to worry about and I was certainly drawing more than 500 objects with gradient fills for some of them!

If you are getting bogged down, you should checkout using PyGame for drawing things.

In my experience, doing things the naive way (drawing each object to the screen) will bog down in Python quicker than C++. However, with Python it's going to be a lot quicker and less painful to code it the clever way (see for example PseudoDC ), which will blow the naive C++ implementation out of the water.

I agree with suraj. above that PyGame may be a good choice, depending on how graphics-intensive the app is, compared to the convenient wxPython stuff you'll be giving up.

For drawing, people have suggested PyGame. I like PyGame, its easy to work with and works well. Other choices would be Pyglet, or using PyOpenGL (you can most likely draw to a wx widget too, though I've never done it).

Personally, I'd do it in Python using whatever library I'm most familiar with (in my case, I'd use pygtk and cairo) and worry about performance only when it becomes a problem - then profile and optimize the bottleneck, if its Python code thats slow, I'll know which bits to run in C instead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM