Re: What is more efficient?
"Gabriel Genellina" <[EMAIL PROTECTED]> wrote in news:[EMAIL PROTECTED]: > It doesn't matter whether you have 0 or a million instances, > methods do not occupy more memory. That's what I was looking for! Thanks, to you and all the others. -- ___Karlo Lozovina - Mosor | | |.-.-. web: http://www.mosor.net || ICQ#: 10667163 | || _ | _ | Parce mihi domine quia Dalmata sum. |__|_|__||_|_| -- http://mail.python.org/mailman/listinfo/python-list
Re: What is more efficient?
Karlo Lozovina wrote: > Let's say I have a class with few string properties and few integers, and > a lot of methods defined for that class. > > Now if I have hundreds of thousands (or even more) of instances of that > class - is it more efficient to remove those methods and make them > separate functions, or it doesn't matter? > > Thanks... > You'd do best to define the instance variable names in __slots__, and be sure to inherit from object. The methods don't matter (they all hang off the class anyway). The __slots__ will save you one reference per object for the __dict__. -- --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: What is more efficient?
On Feb 19, 4:38 pm, Gary Herron <[EMAIL PROTECTED]> wrote: > Karlo Lozovina wrote: > > Let's say I have a class with few string properties and few integers, and > > a lot of methods defined for that class. > > > Now if I have hundreds of thousands (or even more) of instances of that > > class - is it more efficient to remove those methods and make them > > separate functions, or it doesn't matter? > > > Thanks... > > It is not noticeably more or less efficient in either memory or > execution speed. well lucky i wont be designing/creating a new language! > > Both method and function code is compiled and stored once in either the > class name space (for the method) or the module name space (for the > function), and the lookup of either one is a single lookup in the > appropriate name space. > > Actually the method lookup requires one extra step: First look for the > method in the instance (which fails) and then look for it in the class > (which succeeds). But that extra look up is highly optimized and > probably not noticeable. The number of methods/functions may slow things > up, but it will affect either name space equally. > > Gary Herron -- http://mail.python.org/mailman/listinfo/python-list
Re: What is more efficient?
Karlo Lozovina wrote: > Let's say I have a class with few string properties and few integers, and > a lot of methods defined for that class. > > Now if I have hundreds of thousands (or even more) of instances of that > class - is it more efficient to remove those methods and make them > separate functions, or it doesn't matter? > > Thanks... > It is not noticeably more or less efficient in either memory or execution speed. Both method and function code is compiled and stored once in either the class name space (for the method) or the module name space (for the function), and the lookup of either one is a single lookup in the appropriate name space. Actually the method lookup requires one extra step: First look for the method in the instance (which fails) and then look for it in the class (which succeeds). But that extra look up is highly optimized and probably not noticeable. The number of methods/functions may slow things up, but it will affect either name space equally. Gary Herron -- http://mail.python.org/mailman/listinfo/python-list
Re: What is more efficient?
En Mon, 19 Feb 2007 00:17:54 -0300, Karlo Lozovina <[EMAIL PROTECTED]> escribió: > Let's say I have a class with few string properties and few integers, and > a lot of methods defined for that class. > > Now if I have hundreds of thousands (or even more) of instances of that > class - is it more efficient to remove those methods and make them > separate functions, or it doesn't matter? I'm not sure what you mean, but normal methods are attached to the class, not to its instances. It doesn't matter whether you have 0 or a million instances, methods do not occupy more memory. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: What is more efficient?
Hi Karlo, Now if I have hundreds of thousands (or even more) of instances of that class - is it more efficient to remove those methods and make them separate functions, or it doesn't matter? I can't get your idea from your text. Could you give us an example? Thanks... -- ___Karlo Lozovina - Mosor | | |.-.-. web: http://www.mosor.net || ICQ#: 10667163 | || _ | _ | Parce mihi domine quia Dalmata sum. |__|_|__||_|_| -- http://mail.python.org/mailman/listinfo/python-list -- Rintaro Masuda [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: What is more efficient?
On Feb 19, 2:17 pm, Karlo Lozovina <[EMAIL PROTECTED]> wrote: > Let's say I have a class with few string properties and few integers, and > a lot of methods defined for that class. > > Now if I have hundreds of thousands (or even more) of instances of that > class - is it more efficient to remove those methods and make them > separate functions, or it doesn't matter? What do you mean by efficient. Memory efficient? I would assume that making them separate functions would use less memory but would you sacrifice code readability for that (small?) of a memory saving? Good coding practice suggests that the methods should be bound to classes. > > Thanks... > > -- > ___Karlo Lozovina - Mosor > | | |.-.-. web:http://www.mosor.net|| ICQ#: 10667163 > | || _ | _ | Parce mihi domine quia Dalmata sum. > |__|_|__||_|_| Cheers -- http://mail.python.org/mailman/listinfo/python-list
What is more efficient?
Let's say I have a class with few string properties and few integers, and a lot of methods defined for that class. Now if I have hundreds of thousands (or even more) of instances of that class - is it more efficient to remove those methods and make them separate functions, or it doesn't matter? Thanks... -- ___Karlo Lozovina - Mosor | | |.-.-. web: http://www.mosor.net || ICQ#: 10667163 | || _ | _ | Parce mihi domine quia Dalmata sum. |__|_|__||_|_| -- http://mail.python.org/mailman/listinfo/python-list