Created
July 16, 2014 23:00
-
-
Save sloppyfocus/cc04a7409db1c6ef9b85 to your computer and use it in GitHub Desktop.
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
import cProfile | |
import logging | |
import ConfigParser | |
import clusto | |
import time | |
from clusto.drivers import Pool, Driver | |
DB='sqlite:///:memory:' | |
def init_clusto(): | |
conf = ConfigParser.ConfigParser() | |
conf.add_section('clusto') | |
conf.set('clusto', 'dsn', DB) | |
conf.set('clusto', 'versioning', '1') | |
clusto.connect(conf,echo=False) | |
clusto.clear() | |
clusto.SESSION.close() | |
clusto.init_clusto() | |
def preseed_data(): | |
all_pools = [Pool('p%s' % (i+1,)) for i in xrange(100)] | |
parent_pool = Pool('nest0') | |
for i in xrange(10): | |
for j in xrange(10): | |
parent_pool.add_attr('attr%s'%j, 1) | |
nested_pool = Pool('nest%s' % (i+1,)) | |
parent_pool.insert(nested_pool) | |
parent_pool = nested_pool | |
for pool in all_pools: | |
parent_pool.insert(pool) | |
p1 = all_pools[0] | |
p2 = all_pools[1] | |
p1.add_attr('im_a_p1', 1) | |
p1.add_attr('im_a_p2', 1) | |
for pool in all_pools: | |
for i in xrange(5): | |
pool.add_attr('attr%s'%i, 1) | |
for i in xrange(500): | |
d = Driver('d%i' % i) | |
p1.insert(d) | |
if i < 10: | |
p2.insert(d) | |
if i == 5: | |
for pool in all_pools[2:]: | |
pool.insert(d) | |
if __name__ == '__main__': | |
logging.basicConfig() | |
init_clusto() | |
preseed_data() | |
logging.getLogger('sqlalchemy.engine').setLevel(logging.INFO) | |
s1 = clusto.get_by_name('d5') | |
test_start = time.time() | |
cProfile.run("s1.attrs(merge_container_attrs=True)", 'attrs_call') | |
test_attrs_call = time.time() | |
cProfile.run("clusto.get_from_pools(['p1', 'p2'], clusto_types=['server'])", 'get_from_pools_call') | |
test_pool_intersection_call = time.time() | |
print 'Attrs call time: %.4f' % (test_attrs_call - test_start,) | |
print 'Pool intersection time: %.4f' % (test_pool_intersection_call - test_attrs_call,) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment