--- original/benchmark_storm.py 2007-11-24 15:23:24.000000000 -0500 +++ benchmark_storm.py 2007-12-23 19:40:56.000000000 -0500 @@ -1,4 +1,9 @@ -"""Benchmark for Storm.""" +"""Benchmark for Storm. + +Note that the original test omitted the 'step 7 multiview' test which was incomplete, +so its omitted here as well. + +""" import datetime import os @@ -46,6 +51,24 @@ class ZooMark(object): + def setup(self, uri, iterations): + global db, store, ITERATIONS + + db = create_database('postgres://scott:tiger@127.0.0.1/test') + + store = Store(db) + ITERATIONS = iterations + + def teardown(self): + store.close() + conn = db.connect() + conn._raw_connection.set_isolation_level(0) + conn.raw_execute("DROP TABLE Animal", None) + conn.raw_execute("DROP TABLE Zoo", None) + conn.raw_execute("DROP SEQUENCE Animal_ID_seq", None) + conn.raw_execute("DROP SEQUENCE Zoo_ID_seq", None) + conn.close() + def step_1_create_tables(self): # Storm doesn't do CREATE TABLE, etc for you conn = db.connect() @@ -137,19 +160,29 @@ for x in xrange(ITERATIONS): store.add(Animal(Species=u'Tick', Name=u'Tick %d' % x, Legs=8)) + # add flush() so that SQL is actually emitted. otherwise, + # no SQL is emitted in this step (it occurs at the start of step 3). + # adding store.flush() raises the time for 100 iterations from .02 seconds + # to .11 seconds + store.flush() + def step_3_Properties(self): + # use list(store.find(...)) so that the SQL is actually emitted. + # otherwise, no SQL is emitted in this step. + # adding list() raises the time for 100 iterations from .02 seconds (assuming flush() in step 2) + # to 1.5 seconds for x in xrange(ITERATIONS): # Zoos - WAP = store.find(Zoo, Zoo.Name==u'Wild Animal Park') - SDZ = store.find(Zoo, Zoo.Founded==datetime.date(1835, 9, 13)) - Biodome = store.find(Zoo, Zoo.Name==u'Montr\xe9al Biod\xf4me') - seaworld = store.find(Zoo, Zoo.Admission == float(60)) + WAP = list(store.find(Zoo, Zoo.Name==u'Wild Animal Park')) + SDZ = list(store.find(Zoo, Zoo.Founded==datetime.date(1835, 9, 13))) + Biodome = list(store.find(Zoo, Zoo.Name==u'Montr\xe9al Biod\xf4me')) + seaworld = list(store.find(Zoo, Zoo.Admission == float(60))) # Animals - leopard = store.find(Animal, Animal.Species == u'Leopard') - ostrich = store.find(Animal, Animal.Species==u'Ostrich') - millipede = store.find(Animal, Animal.Legs==1000000) - ticks = store.find(Animal, Animal.Species==u'Tick') + leopard = list(store.find(Animal, Animal.Species == u'Leopard')) + ostrich = list(store.find(Animal, Animal.Species==u'Ostrich')) + millipede = list(store.find(Animal, Animal.Legs==1000000)) + ticks = list(store.find(Animal, Animal.Species==u'Tick')) def step_4_Expressions(self): for x in xrange(ITERATIONS): @@ -178,10 +211,6 @@ assert len(list(store.find(Animal, Animal.Species.is_in((pet.Name, pet2.Name))))) == 2 # logic and other functions -## class ILIKE(storm.expr.NamedFunc): -## name = "ilike" -## assert len(list(store.find(Animal, Animal.Species.ilike(u'slug')))) == 1 -## assert len(list(store.find(Animal, Animal.Species.ilike(u'%PEDE%')))) == 2 class LENGTH(storm.expr.NamedFunc): name = "LENGTH" name = 'Lion' @@ -226,8 +255,10 @@ assert lifespan == expected[species] expected = [u'Montr\xe9al Biod\xf4me', u'Wild Animal Park'] + # changed "datetime.now()" to be "date.today()" to provide type + # consistency (other platforms require it) e = getall([Zoo.Name], storm.expr.And(Zoo.Founded != None, - Zoo.Founded <= datetime.datetime.now(), + Zoo.Founded <= datetime.date.today(), Zoo.Founded >= datetime.date(1990, 1, 1))) values = [val[0] for val in e] assert set(values) == set(expected) @@ -260,96 +291,3 @@ # Test re-edits SDZ = store.find(Zoo, Zoo.Name==u'San Diego Zoo')[0] assert SDZ.Founded == datetime.date(1835, 9, 13), SDZ.Founded -## -## def step_7_Multiview(self): -## animkeys = [col.name for col in Animal._storm_columns.itervalues()] -## -## for x in xrange(ITERATIONS): -## za = list(store.find((Zoo, Animal), -## storm.expr.And(Zoo.ID == Animal.ZooID, -## Zoo.Name == u'San Diego Zoo'))) -## -## SDZ = store.find(Zoo, Zoo.Name==u'San Diego Zoo')[0] -## -## origin = [Zoo, Join(Animal, Animal.ZooID == Zoo.ID)] -## e = store.using(*origin).find((Zoo, Animal), -## storm.expr.And(Zoo.Name==u'San Diego Zoo', -## Animal.Species==u'Leopard') -## ) -## -## # Now try the same query with INNER, LEFT, and RIGHT JOINs. -## e = fulltable(select([Zoo.Name, Animal.Species], -## from_obj=[join(Zoo, Animal)])) -## e = fulltable(select([Zoo.Name, Animal.Species], -## from_obj=[outerjoin(Zoo, Animal)])) -## e = fulltable(select([Zoo.Name, Animal.Species], -## from_obj=[outerjoin(Animal, Zoo)])) - - - -db = None -store = None - -def run(pw): - global db, store - try: - # Create database - db = create_database('postgres://postgres:%s@localhost/template1' % pw) - conn = db.connect() - conn._raw_connection.set_isolation_level(0) - conn.raw_execute("CREATE DATABASE storm_bench", params=None) - conn.close() - - db = create_database('postgres://postgres:%s@localhost/storm_bench' % pw) - store = Store(db) - - zm = ZooMark() - for method in [x for x in dir(zm) if x.startswith("step_")]: - startTime = datetime.datetime.now() - meth = getattr(zm, method) - if conquer: - import pyconquer - events = ['call', 'return', 'exception'] -## events.extend(['c_call', 'c_return', 'c_exception']) - tr = pyconquer.Logger(events=events) - tr.out = open(os.path.join(thisdir, "storm_%s.log" % method), "wb") - tr.time_calls = True - try: - tr.start() - meth() - finally: - tr.stop() - tr.out.close() - else: - try: - meth() - except: - import traceback - traceback.print_exc() - print "Ran %s in: %s" % (method, datetime.datetime.now() - startTime) - finally: - try: - store.close() - except AttributeError: - pass - - try: - db = create_database('postgres://postgres:%s@localhost/template1' % pw) - conn = db.connect() - conn._raw_connection.set_isolation_level(0) - conn.raw_execute("DROP DATABASE storm_bench", params=None) - conn.close() - except NotImplementedError: - pass - - -ITERATIONS = 100 - -if __name__ == '__main__': - args = sys.argv[1:] - if args: - ITERATIONS = int(args[-1]) - conquer = "--conquer" in args - - run(raw_input("Postgres password:")) -