473,509 Members | 2,828 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Speed of data structures in python


Hi. I am learning PyOpenGL and I am working with a largish fixed scene
composed of several thousand GLtriangles. I plan to store the coords and
normals in a NumPy array.

Is this the fastest solution in python? would i be significantly better
off (timewise or otherwise) using some other data structure to hold this
information? no other data structure appears as convenient, but am i
loosing valuable time?

I am new to 3d programming so please feel free to state the obvious,
thanks.

Dave.
--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/

Mar 10 '06 #1
4 2207
On Fri, 10 Mar 2006 23:24:46 +1100, Dave wrote:

Hi. I am learning PyOpenGL and I am working with a largish fixed scene
composed of several thousand GLtriangles. I plan to store the coords and
normals in a NumPy array.

Is this the fastest solution in python? would i be significantly better
off (timewise or otherwise) using some other data structure to hold this
information? no other data structure appears as convenient, but am i
loosing valuable time?

I am new to 3d programming so please feel free to state the obvious,
thanks.

Optimization without measurement is at best a waste of time and at worst
counter-productive. Why don't you time your code and see if it is fast
enough?

See the timeit module, and the profiler.
--
Steven.

Mar 11 '06 #2
On Sat, 11 Mar 2006 13:12:30 +1100
"Steven D'Aprano" <st***@REMOVETHIScyber.com.au> wrote:
On Fri, 10 Mar 2006 23:24:46 +1100, Dave wrote:
Hi. I am learning PyOpenGL and I am working with a
largish fixed scene composed of several thousand
GLtriangles. I plan to store the coords and normals in
a NumPy array.

Is this the fastest solution in python?
Optimization without measurement is at best a waste of
time and at worst counter-productive. Why don't you time
your code and see if it is fast enough?

See the timeit module, and the profiler.


Talk about knee-jerk reactions. ;-)

It's a *3D animation* module -- of course it's going to be
time-critical. Sheesh. Now *that* is stating the obvious.

The obvious solution is actually a list of tuples. But
it's very possible that that won't be fast enough, so the
NumPy approach may be a significant speedup. I doubt you
need more than that, though.

I think the real question is not going to be how fast your
code handles data, though, but rather how fast you can get
that data into PyOpenGL and back. So the real fastest format
is going to be "whatever PyOpenGL uses" -- so I'd look that
up.

For comparison, SDL uses "surfaces" to store 2D data, so
when programming in PyGame, your first step is to load every
image into a surface. Once there, display to the screen is
very very fast -- but moving from image to surface is
typically slow, no matter how spiffy your image format may
be internally. I suspect something similar applies to
PyOpenGL.

--
Terry Hancock (ha*****@AnansiSpaceworks.com)
Anansi Spaceworks http://www.AnansiSpaceworks.com

Mar 11 '06 #3
On Fri, 10 Mar 2006 21:06:27 -0600, Terry Hancock wrote:
On Sat, 11 Mar 2006 13:12:30 +1100
"Steven D'Aprano" <st***@REMOVETHIScyber.com.au> wrote:
On Fri, 10 Mar 2006 23:24:46 +1100, Dave wrote:
> Hi. I am learning PyOpenGL and I am working with a
> largish fixed scene composed of several thousand
> GLtriangles. I plan to store the coords and normals in
> a NumPy array.
>
> Is this the fastest solution in python?
Optimization without measurement is at best a waste of
time and at worst counter-productive. Why don't you time
your code and see if it is fast enough?

See the timeit module, and the profiler.


Talk about knee-jerk reactions. ;-)


Yes, let's.
It's a *3D animation* module -- of course it's going to be
time-critical. Sheesh. Now *that* is stating the obvious.
Did I say it wasn't? I asked if the current solution is fast enough. If
the current solution is fast enough, then why waste time trying to speed
it up? Does the Original Poster think that PCs will get slower in the
future?

The obvious solution is actually a list of tuples.
But that's not the solution being asked about, nor did I suggest it.

But
it's very possible that that won't be fast enough, so the
NumPy approach may be a significant speedup. I doubt you
need more than that, though.


I didn't argue against the NumPy approach. I suggested that, instead of
*asking* if there was something faster, the O.P. should actually *try it*
and see if it is fast enough.

If you think that is bad advice, please tell us what you consider good
advice.

--
Steven.

Mar 11 '06 #4

As the OP, i thought i'd follow up with my experience, in case anyone else
is learning pyopengl and as mystified as i was (am?).

Thank you to all the posters who responded, especially the one who
mentioned display lists...

Initially, i had built a very simple prototype, getting 5 fps. This was
very poorly designed though, calculating normals and positions (sqrt, sin,
pow) on the fly.

when i posted the OP, i suspecteded that the biggest improvement would be
achieved by storing the normals and positions in the fastest data
structure.

after posting, i implemented numpy arrays to hold normals and positions,
and got 18 fps.

i then increased the complexity of the protoype to the bare-min specs
required, and got 1-2 fps.

i then implemented display lists (opengl stuff), and am now getting 190
fps (on the larger protoype).

so, my point is, the limiting factor had nothing to do with speed of data
structures in python, but the way data was being consumed by opengl (and
my absolute newbieness at opengl ;-)

i hope this helps anyone who is learning similar material

Dave

On Sat, 11 Mar 2006 16:54:06 +1100, Steven D'Aprano
<st***@REMOVETHIScyber.com.au> wrote:
On Fri, 10 Mar 2006 21:06:27 -0600, Terry Hancock wrote:
On Sat, 11 Mar 2006 13:12:30 +1100
"Steven D'Aprano" <st***@REMOVETHIScyber.com.au> wrote:
On Fri, 10 Mar 2006 23:24:46 +1100, Dave wrote:
> Hi. I am learning PyOpenGL and I am working with a
> largish fixed scene composed of several thousand
> GLtriangles. I plan to store the coords and normals in
> a NumPy array.
>
> Is this the fastest solution in python?

Optimization without measurement is at best a waste of
time and at worst counter-productive. Why don't you time
your code and see if it is fast enough?

See the timeit module, and the profiler.


Talk about knee-jerk reactions. ;-)


Yes, let's.
It's a *3D animation* module -- of course it's going to be
time-critical. Sheesh. Now *that* is stating the obvious.


Did I say it wasn't? I asked if the current solution is fast enough. If
the current solution is fast enough, then why waste time trying to speed
it up? Does the Original Poster think that PCs will get slower in the
future?

The obvious solution is actually a list of tuples.


But that's not the solution being asked about, nor did I suggest it.

But
it's very possible that that won't be fast enough, so the
NumPy approach may be a significant speedup. I doubt you
need more than that, though.


I didn't argue against the NumPy approach. I suggested that, instead of
*asking* if there was something faster, the O.P. should actually *try it*
and see if it is fast enough.

If you think that is bad advice, please tell us what you consider good
advice.


--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/

Mar 13 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

34
2438
by: Jacek Generowicz | last post by:
I have a program in which I make very good use of a memoizer: def memoize(callable): cache = {} def proxy(*args): try: return cache except KeyError: return cache.setdefault(args,...
52
3795
by: Neuruss | last post by:
It seems there are quite a few projects aimed to improve Python's speed and, therefore, eliminate its main limitation for mainstream acceptance. I just wonder what do you all think? Will Python...
11
2716
by: Fred Bennett | last post by:
I have a simulation project in which data can naturally be held in structures for processing. There are calls to multiple functions involved. Execution speed is an issue. Do I take a big hit for...
0
934
by: bearophileHUGS | last post by:
ShedSkin (http://shed-skin.blogspot.com) has taught me something: simple syntax and high speed can often go together, in a computer language. This means two things: 1) A "fast language" can...
0
1157
by: Steve Holden | last post by:
EWT LLC and CCP h.f., having specific commercial interests in doing so, have decided to sponsor a sprint on the Python programming language with specific short- and medium-term acceleration goals....
11
3731
by: efrat | last post by:
Hello, I'm planning to use Python in order to teach a DSA (data structures and algorithms) course in an academic institute. If you could help out with the following questions, I'd sure...
9
2730
by: tom arnall | last post by:
does anyone know of a utility to do a recursive dump of object data members? -- Posted via a free Usenet account from http://www.teranews.com
17
1451
by: Suresh Pillai | last post by:
I am performing simulations on networks (graphs). I have a question on speed of execution (assuming very ample memory for now). I simplify the details of my simulation below, as the question I...
0
255
by: Chris Rebert | last post by:
On Wed, Oct 8, 2008 at 5:34 PM, Warren DeLano <warren@delsci.comwrote: Assuming the data structures are sufficiently basic, i.e. no class instanciations, you can just use the json (AKA...
0
7237
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7137
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7347
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7073
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
5062
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3218
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3207
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
779
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
443
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.