Created
March 2, 2012 21:22
-
-
Save dsuch/1961505 to your computer and use it in GitHub Desktop.
SimpleBunch vs. Bunch vs. dict
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
# stdlib | |
from timeit import Timer | |
# Bunch | |
import bunch | |
d = {1:11, 2:22, 3:33} | |
b = bunch.Bunch(d) | |
sb = bunch.SimpleBunch(d) | |
def test_dict(): | |
d['aa'] = 'bb' | |
d['aa'] = 'bb' | |
'aa' in d | |
del d['aa'] | |
def test_bunch(): | |
b.aa = 'bb' | |
b.aa = 'bb' | |
'aa' in b | |
del b['aa'] | |
def test_bunch_c(): | |
sb.aa = 'bb' | |
sb.aa = 'bb' | |
'aa' in sb | |
del sb['aa'] | |
if __name__ == '__main__': | |
loops = 300 | |
for x in range(1, loops+1): | |
print('-' * 40) | |
print('Loop #{}/{}'.format(x, loops)) | |
print('-' * 40) | |
print('Bunch (C) -->', Timer('test_bunch_c()', 'from __main__ import test_bunch_c').repeat()) | |
print('Bunch -->', Timer('test_bunch()', 'from __main__ import test_bunch').repeat()) | |
print('Dict -->', Timer('test_dict()', 'from __main__ import test_dict').repeat()) | |
print('\n') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment