[New-bugs-announce] [issue2115] __slots__ make attribute setting 10x slower

Jeffrey Yasskin report at bugs.python.org
Thu Feb 14 19:01:38 CET 2008


New submission from Jeffrey Yasskin:

(On a MacBook Pro 2.33 GHz)

$ ./python.exe -m timeit -s 'class Foo(object): pass' -s 'f = Foo()'
'f.num = 3'
10000000 loops, best of 3: 0.13 usec per loop
$ ./python.exe -m timeit -s 'class Foo(object): __slots__ = ["num"]' -s
'f = Foo()' 'f.num = 3'
1000000 loops, best of 3: 1.24 usec per loop

Attribute reading isn't affected:
$ ./python.exe -m timeit -s 'class Foo(object): pass' -s 'f = Foo();
f.num = 3' 'g = f.num'
10000000 loops, best of 3: 0.107 usec per loop
$ ./python.exe -m timeit -s 'class Foo(object): __slots__ = ["num"]' -s
'f = Foo(); f.num = 3' 'g = f.num'
10000000 loops, best of 3: 0.101 usec per loop

----------
components: Interpreter Core
messages: 62408
nosy: jyasskin
severity: normal
status: open
title: __slots__ make attribute setting 10x slower
type: resource usage
versions: Python 2.6

__________________________________
Tracker <report at bugs.python.org>
<http://bugs.python.org/issue2115>
__________________________________


More information about the New-bugs-announce mailing list