Skip to content

Instantly share code, notes, and snippets.

@timothycrosley
Last active April 25, 2016 01:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timothycrosley/ddd4c07d1312831207b8d3381ff44f12 to your computer and use it in GitHub Desktop.
Save timothycrosley/ddd4c07d1312831207b8d3381ff44f12 to your computer and use it in GitHub Desktop.
%cpaste
import time
class Test(object):
__slots__ = ('a', 'b', 'c')
def __init__(self):
self.a = 1
self.b = 1
self.c = 1
class Test2(object):
temp = Test()
temp2 = Test()
temp3 = Test()
start = time.time()
for x in xrange(1000000000):
Test2()
print("With slots:{0}".format(time.time() - start))
--
%cpaste
import time
class Test(object):
#__slots__ = ('a', 'b', 'c')
def __init__(self):
self.a = 1
self.b = 1
self.c = 1
class Test2(object):
temp = Test()
temp2 = Test()
temp3 = Test()
start = time.time()
for x in xrange(1000000000):
Test2()
print("Without slots:{0}".format(time.time() - start))
--
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment