Skip to content

Instantly share code, notes, and snippets.

@Tukki
Last active September 26, 2016 11:23
Show Gist options
  • Save Tukki/670be24c7b21cb3fbed717b673799a42 to your computer and use it in GitHub Desktop.
Save Tukki/670be24c7b21cb3fbed717b673799a42 to your computer and use it in GitHub Desktop.
python setattr test
# _*_ coding: utf-8 _*_
# http://stackoverflow.com/questions/12798653/does-setattr-and-getattr-slow-down-the-speed-dramatically
# run: time python setattr_test.py
class O(object):
pass
o = O()
for i in xrange(10000000):
setattr(o, 'a', 1) # python setattr_test.py 1.44s user 0.01s system 99% cpu 1.449 total
#o.a = 1 # python setattr_test.py 0.68s user 0.00s system 99% cpu 0.686 total
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment