Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #77740 > unrolled thread
| Started by | Michael Torrie <torriem@gmail.com> |
|---|---|
| First post | 2014-09-09 09:32 -0600 |
| Last post | 2014-09-09 09:32 -0600 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: weakref, memory management and execution slow down in PyQt4 Michael Torrie <torriem@gmail.com> - 2014-09-09 09:32 -0600
| From | Michael Torrie <torriem@gmail.com> |
|---|---|
| Date | 2014-09-09 09:32 -0600 |
| Subject | Re: weakref, memory management and execution slow down in PyQt4 |
| Message-ID | <mailman.13904.1410276758.18130.python-list@python.org> |
Reposting to list, instead of directly to kjs On 09/08/2014 08:45 PM, kjs wrote: > Thanks for the consideration Michael. If you do get the data, and are > able to run the code, let me know if you notice anything interesting. Yeah I don't think I'll be able to have the time to download a 3 GB file. >> Is there a reason you are using setattr and getattr instead of a proper >> data structure? both of those calls are rather expensive. Would >> probably be cheaper to use some kind of array, dictionary, or other >> purpose-built data structure? >> > > You're right, a dictionary can do everything I need and more. This > happened to be the first thing I thought of, and I didn't imagine it > would be very expensive. I figured it was simply a different way of > defining and retrieving a class variable. IE setattr(self, foo, True) == > self.foo = True. Yes you're correct. It is the equivalent. But it always involves lookup in the object's dictionary, which is big O order O(n log n) complexity for each and every access. A list would be far faster, essentially O(1) (I think?) after the single name lookup, since you can access the elements by number. Indexing into a list doesn't involve doing name lookups; you just specify an offset. No idea how much faster, but significantly so. If a list is too slow, there are other array-like classes you can use (like numpy arrays) that do offer true O(1) lookups. Besides that, it's not typical use of setattr and getattr in python.
Back to top | Article view | comp.lang.python
csiph-web