Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #77740
| Date | 2014-09-09 09:32 -0600 |
|---|---|
| From | Michael Torrie <torriem@gmail.com> |
| Subject | Re: weakref, memory management and execution slow down in PyQt4 |
| References | (2 earlier) <540CADDD.3050501@riseup.net> <540CB15C.2060008@gmail.com> <540CC278.4050106@riseup.net> <540E40FD.8030706@gmail.com> <540E69AF.5040309@riseup.net> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.13904.1410276758.18130.python-list@python.org> (permalink) |
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 comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: weakref, memory management and execution slow down in PyQt4 Michael Torrie <torriem@gmail.com> - 2014-09-09 09:32 -0600
csiph-web