summaryrefslogtreecommitdiff
path: root/test/perf
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2013-04-27 19:53:57 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2013-04-27 19:53:57 -0400
commit4b614b9b35cd2baddb7ca67c04bee5d70ec6a172 (patch)
tree7483cd269f5823f903f96709eb864fff9b6d9383 /test/perf
parent9716a5c45e6185c5871555722d8495880f0e8c7a (diff)
downloadsqlalchemy-4b614b9b35cd2baddb7ca67c04bee5d70ec6a172.tar.gz
- the raw 2to3 run
- went through examples/ and cleaned out excess list() calls
Diffstat (limited to 'test/perf')
-rw-r--r--test/perf/insertspeed.py18
-rw-r--r--test/perf/objselectspeed.py8
-rw-r--r--test/perf/objupdatespeed.py8
-rw-r--r--test/perf/orm2010.py18
-rw-r--r--test/perf/ormsession.py8
-rw-r--r--test/perf/stress_all.py30
-rw-r--r--test/perf/stresstest.py28
-rw-r--r--test/perf/threaded_compile.py22
8 files changed, 70 insertions, 70 deletions
diff --git a/test/perf/insertspeed.py b/test/perf/insertspeed.py
index 03d2c4144..88e73fef9 100644
--- a/test/perf/insertspeed.py
+++ b/test/perf/insertspeed.py
@@ -13,18 +13,18 @@ Person_table = Table('Person', metadata,
def sa_unprofiled_insertmany(n):
i = Person_table.insert()
- i.execute([{'name':'John Doe','sex':1,'age':35} for j in xrange(n)])
+ i.execute([{'name':'John Doe','sex':1,'age':35} for j in range(n)])
def sqlite_unprofiled_insertmany(n):
conn = db.connect().connection
c = conn.cursor()
- persons = [('john doe', 1, 35) for i in xrange(n)]
+ persons = [('john doe', 1, 35) for i in range(n)]
c.executemany("insert into Person(name, sex, age) values (?,?,?)", persons)
@profiling.profiled('sa_profiled_insert_many', always=True)
def sa_profiled_insert_many(n):
i = Person_table.insert()
- i.execute([{'name':'John Doe','sex':1,'age':35} for j in xrange(n)])
+ i.execute([{'name':'John Doe','sex':1,'age':35} for j in range(n)])
s = Person_table.select()
r = s.execute()
res = [[value for value in row] for row in r.fetchall()]
@@ -32,7 +32,7 @@ def sa_profiled_insert_many(n):
def sqlite_unprofiled_insert(n):
conn = db.connect().connection
c = conn.cursor()
- for j in xrange(n):
+ for j in range(n):
c.execute("insert into Person(name, sex, age) values (?,?,?)",
('john doe', 1, 35))
@@ -40,13 +40,13 @@ def sa_unprofiled_insert(n):
# Another option is to build Person_table.insert() outside of the
# loop. But it doesn't make much of a difference, so might as well
# use the worst-case/naive version here.
- for j in xrange(n):
+ for j in range(n):
Person_table.insert().execute({'name':'John Doe','sex':1,'age':35})
@profiling.profiled('sa_profiled_insert', always=True)
def sa_profiled_insert(n):
i = Person_table.insert()
- for j in xrange(n):
+ for j in range(n):
i.execute({'name':'John Doe','sex':1,'age':35})
s = Person_table.select()
r = s.execute()
@@ -69,12 +69,12 @@ def run_profiled(fn, label, *args, **kw):
metadata.drop_all()
metadata.create_all()
- print "%s (%s)" % (label, ', '.join([str(a) for a in args]))
+ print("%s (%s)" % (label, ', '.join([str(a) for a in args])))
fn(*args, **kw)
def all():
try:
- print "Bulk INSERTS via executemany():\n"
+ print("Bulk INSERTS via executemany():\n")
run_timed(sqlite_unprofiled_insertmany,
'pysqlite bulk insert',
@@ -88,7 +88,7 @@ def all():
'SQLAlchemy bulk insert/select, profiled',
50000)
- print "\nIndividual INSERTS via execute():\n"
+ print("\nIndividual INSERTS via execute():\n")
run_timed(sqlite_unprofiled_insert,
"pysqlite individual insert",
diff --git a/test/perf/objselectspeed.py b/test/perf/objselectspeed.py
index c0ed88444..dc790ab17 100644
--- a/test/perf/objselectspeed.py
+++ b/test/perf/objselectspeed.py
@@ -36,7 +36,7 @@ def setup():
metadata.create_all()
i = Person_table.insert()
data = [{'name':'John Doe','sex':1,'age':35, 'type':'employee'}] * 100
- for j in xrange(500):
+ for j in range(500):
i.execute(data)
# note we arent fetching from employee_table,
@@ -46,7 +46,7 @@ def setup():
#for j in xrange(500):
# i.execute(data)
- print "Inserted 50,000 rows"
+ print("Inserted 50,000 rows")
def sqlite_select(entity_cls):
conn = db.connect().connection
@@ -89,10 +89,10 @@ def all():
t, t2 = 0, 0
def usage(label):
now = resource.getrusage(resource.RUSAGE_SELF)
- print "%s: %0.3fs real, %0.3fs user, %0.3fs sys" % (
+ print("%s: %0.3fs real, %0.3fs user, %0.3fs sys" % (
label, t2 - t,
now.ru_utime - usage.last.ru_utime,
- now.ru_stime - usage.last.ru_stime)
+ now.ru_stime - usage.last.ru_stime))
usage.snap(now)
usage.snap = lambda stats=None: setattr(
usage, 'last', stats or resource.getrusage(resource.RUSAGE_SELF))
diff --git a/test/perf/objupdatespeed.py b/test/perf/objupdatespeed.py
index 98d10180e..95a5fbc9b 100644
--- a/test/perf/objupdatespeed.py
+++ b/test/perf/objupdatespeed.py
@@ -39,12 +39,12 @@ def setup():
i.execute(data)
i = Email_table.insert()
- for j in xrange(1, NUM + 1):
+ for j in range(1, NUM + 1):
i.execute(address='foo@bar', person_id=j)
if j % 2:
i.execute(address='baz@quux', person_id=j)
- print "Inserted %d rows." % (NUM + NUM + (NUM // 2))
+ print("Inserted %d rows." % (NUM + NUM + (NUM // 2)))
def orm_select(session):
return session.query(Person).all()
@@ -63,10 +63,10 @@ def all():
t, t2 = 0, 0
def usage(label):
now = resource.getrusage(resource.RUSAGE_SELF)
- print "%s: %0.3fs real, %0.3fs user, %0.3fs sys" % (
+ print("%s: %0.3fs real, %0.3fs user, %0.3fs sys" % (
label, t2 - t,
now.ru_utime - usage.last.ru_utime,
- now.ru_stime - usage.last.ru_stime)
+ now.ru_stime - usage.last.ru_stime))
usage.snap(now)
usage.snap = lambda stats=None: setattr(
usage, 'last', stats or resource.getrusage(resource.RUSAGE_SELF))
diff --git a/test/perf/orm2010.py b/test/perf/orm2010.py
index 47257ba87..937e6ddff 100644
--- a/test/perf/orm2010.py
+++ b/test/perf/orm2010.py
@@ -95,7 +95,7 @@ def runit():
name="Boss %d" % i,
golf_average=Decimal(random.randint(40, 150))
)
- for i in xrange(1000)
+ for i in range(1000)
]
sess.add_all(bosses)
@@ -107,7 +107,7 @@ def runit():
name="Grunt %d" % i,
savings=Decimal(random.randint(5000000, 15000000) / 100)
)
- for i in xrange(10000)
+ for i in range(10000)
]
# Assign each Grunt a Boss. Look them up in the DB
@@ -149,15 +149,15 @@ stats = pstats.Stats(filename)
counts_by_methname = dict((key[2], stats.stats[key][0]) for key in stats.stats)
-print "SQLA Version: %s" % __version__
-print "Total calls %d" % stats.total_calls
-print "Total cpu seconds: %.2f" % stats.total_tt
-print 'Total execute calls: %d' \
+print("SQLA Version: %s" % __version__)
+print("Total calls %d" % stats.total_calls)
+print("Total cpu seconds: %.2f" % stats.total_tt)
+print('Total execute calls: %d' \
% counts_by_methname["<method 'execute' of 'sqlite3.Cursor' "
- "objects>"]
-print 'Total executemany calls: %d' \
+ "objects>"])
+print('Total executemany calls: %d' \
% counts_by_methname.get("<method 'executemany' of 'sqlite3.Cursor' "
- "objects>", 0)
+ "objects>", 0))
#stats.sort_stats('time', 'calls')
#stats.print_stats()
diff --git a/test/perf/ormsession.py b/test/perf/ormsession.py
index 5e38d6e80..2fc656117 100644
--- a/test/perf/ormsession.py
+++ b/test/perf/ormsession.py
@@ -81,9 +81,9 @@ def insert_data():
transaction = con.begin()
data, subdata = [], []
- for item_id in xrange(1, q_items + 1):
+ for item_id in range(1, q_items + 1):
data.append({'name': "item number %s" % item_id})
- for subitem_id in xrange(1, (item_id % q_sub_per_item) + 1):
+ for subitem_id in range(1, (item_id % q_sub_per_item) + 1):
subdata.append({'item_id': item_id,
'name': "subitem number %s" % subitem_id})
if item_id % 100 == 0:
@@ -99,7 +99,7 @@ def insert_data():
transaction = con.begin()
data = []
- for customer_id in xrange(1, q_customers):
+ for customer_id in range(1, q_customers):
data.append({'name': "customer number %s" % customer_id})
if customer_id % 100 == 0:
customers.insert().execute(*data)
@@ -111,7 +111,7 @@ def insert_data():
transaction = con.begin()
data, subdata = [], []
order_t = int(time.time()) - (5000 * 5 * 60)
- current = xrange(1, q_customers)
+ current = range(1, q_customers)
step, purchase_id = 1, 0
while current:
next = []
diff --git a/test/perf/stress_all.py b/test/perf/stress_all.py
index 890ef24a3..b2e034e7d 100644
--- a/test/perf/stress_all.py
+++ b/test/perf/stress_all.py
@@ -2,7 +2,7 @@
from datetime import *
import decimal
#from fastdec import mpd as Decimal
-from cPickle import dumps, loads
+from pickle import dumps, loads
#from sqlalchemy.dialects.postgresql.base import ARRAY
@@ -42,9 +42,9 @@ def getitem_int_results(raw_results):
def getitem_long_results(raw_results):
return [
- (r[0L],
- r[1L], r[2L], r[3L], r[4L], r[5L],
- r[6L], r[7L], r[8L], r[9L], r[10L])
+ (r[0],
+ r[1], r[2], r[3], r[4], r[5],
+ r[6], r[7], r[8], r[9], r[10])
for r in raw_results]
def getitem_obj_results(raw_results):
@@ -128,7 +128,7 @@ typedecoratortest = (MyIntType, genmyintvalue,
# Unicode
def genunicodevalue(rnum, fnum):
- return (rnum % 4) and (u"value%d" % fnum) or None
+ return (rnum % 4) and ("value%d" % fnum) or None
unicodetest = (Unicode(20, ), genunicodevalue,
dict(num_records=100000))
# dict(engineurl='mysql:///test', freshdata=False))
@@ -139,10 +139,10 @@ if test_types:
pickletypetest, typedecoratortest, unicodetest]
for engineurl in ('postgresql://scott:tiger@localhost/test',
'sqlite://', 'mysql://scott:tiger@localhost/test'):
- print "\n%s\n" % engineurl
+ print("\n%s\n" % engineurl)
for datatype, genvalue, kwargs in tests:
- print "%s:" % getattr(datatype, '__name__',
- datatype.__class__.__name__),
+ print("%s:" % getattr(datatype, '__name__',
+ datatype.__class__.__name__), end=' ')
profile_and_time_dbfunc(iter_results, datatype, genvalue,
profile=False, engineurl=engineurl,
verbose=verbose, **kwargs)
@@ -158,13 +158,13 @@ if test_methods:
slice_results]
for engineurl in ('postgresql://scott:tiger@localhost/test',
'sqlite://', 'mysql://scott:tiger@localhost/test'):
- print "\n%s\n" % engineurl
+ print("\n%s\n" % engineurl)
test_table = prepare(Unicode(20,),
genunicodevalue,
num_fields=10, num_records=100000,
verbose=verbose, engineurl=engineurl)
for method in methods:
- print "%s:" % method.__name__,
+ print("%s:" % method.__name__, end=' ')
time_dbfunc(test_table, method, genunicodevalue,
num_fields=10, num_records=100000, profile=False,
verbose=verbose)
@@ -174,9 +174,9 @@ if test_methods:
# --------------------------------
def pickletofile_results(raw_results):
- from cPickle import dump, load
+ from pickle import dump, load
for protocol in (0, 1, 2):
- print "dumping protocol %d..." % protocol
+ print("dumping protocol %d..." % protocol)
f = file('noext.pickle%d' % protocol, 'wb')
dump(raw_results, f, protocol)
f.close()
@@ -198,7 +198,7 @@ if test_pickle:
num_fields=10, num_records=10000)
funcs = [pickle_rows, pickle_results]
for func in funcs:
- print "%s:" % func.__name__,
+ print("%s:" % func.__name__, end=' ')
time_dbfunc(test_table, func, genunicodevalue,
num_records=10000, profile=False, verbose=verbose)
@@ -217,9 +217,9 @@ if test_orm:
def get_results():
return session.query(Test).all()
- print "ORM:",
+ print("ORM:", end=' ')
for engineurl in ('postgresql:///test', 'sqlite://', 'mysql:///test'):
- print "\n%s\n" % engineurl
+ print("\n%s\n" % engineurl)
profile_and_time_dbfunc(getattr_results, Unicode(20), genunicodevalue,
class_=Test, getresults_func=get_results,
engineurl=engineurl, #freshdata=False,
diff --git a/test/perf/stresstest.py b/test/perf/stresstest.py
index cf9404f53..ca7c1da4f 100644
--- a/test/perf/stresstest.py
+++ b/test/perf/stresstest.py
@@ -17,13 +17,13 @@ def gen_table(num_fields, field_type, metadata):
def insert(test_table, num_fields, num_records, genvalue, verbose=True):
if verbose:
- print "building insert values...",
+ print("building insert values...", end=' ')
sys.stdout.flush()
values = [dict(("field%d" % fnum, genvalue(rnum, fnum))
for fnum in range(num_fields))
for rnum in range(num_records)]
if verbose:
- print "inserting...",
+ print("inserting...", end=' ')
sys.stdout.flush()
def db_insert():
test_table.insert().execute(values)
@@ -32,11 +32,11 @@ def insert(test_table, num_fields, num_records, genvalue, verbose=True):
"from __main__ import db_insert",
number=1)
if verbose:
- print "%s" % round(timing, 3)
+ print("%s" % round(timing, 3))
def check_result(results, num_fields, genvalue, verbose=True):
if verbose:
- print "checking...",
+ print("checking...", end=' ')
sys.stdout.flush()
for rnum, row in enumerate(results):
expected = tuple([rnum + 1] +
@@ -49,28 +49,28 @@ def avgdev(values, comparison):
def nicer_res(values, printvalues=False):
if printvalues:
- print values
+ print(values)
min_time = min(values)
return round(min_time, 3), round(avgdev(values, min_time), 2)
def profile_func(func_name, verbose=True):
if verbose:
- print "profiling...",
+ print("profiling...", end=' ')
sys.stdout.flush()
cProfile.run('%s()' % func_name, 'prof')
def time_func(func_name, num_tests=1, verbose=True):
if verbose:
- print "timing...",
+ print("timing...", end=' ')
sys.stdout.flush()
timings = timeit.repeat('%s()' % func_name,
"from __main__ import %s" % func_name,
number=num_tests, repeat=5)
avg, dev = nicer_res(timings)
if verbose:
- print "%s (%s)" % (avg, dev)
+ print("%s (%s)" % (avg, dev))
else:
- print avg
+ print(avg)
def profile_and_time(func_name, num_tests=1):
profile_func(func_name)
@@ -121,7 +121,7 @@ def time_dbfunc(test_table, test_func, genvalue,
check_results=check_result, profile=True,
check_leaks=True, print_leaks=False, verbose=True):
if verbose:
- print "testing '%s'..." % test_func.__name__,
+ print("testing '%s'..." % test_func.__name__, end=' ')
sys.stdout.flush()
if class_ is not None:
clear_mappers()
@@ -148,12 +148,12 @@ def time_dbfunc(test_table, test_func, genvalue,
diff = hashable_objects_after - hashable_objects_before
ldiff = len(diff)
if print_leaks and ldiff < num_records:
- print "\n*** hashable objects leaked (%d) ***" % ldiff
- print '\n'.join(map(str, diff))
- print "***\n"
+ print("\n*** hashable objects leaked (%d) ***" % ldiff)
+ print('\n'.join(map(str, diff)))
+ print("***\n")
if num_leaks > num_records:
- print "(leaked: %d !)" % num_leaks,
+ print("(leaked: %d !)" % num_leaks, end=' ')
if profile:
profile_func('test', verbose)
time_func('test', num_tests, verbose)
diff --git a/test/perf/threaded_compile.py b/test/perf/threaded_compile.py
index 0facf0ec2..23474a1c6 100644
--- a/test/perf/threaded_compile.py
+++ b/test/perf/threaded_compile.py
@@ -4,7 +4,7 @@ collection is being compiled."""
from sqlalchemy import *
from sqlalchemy.orm import *
-import thread, time
+import _thread, time
from sqlalchemy.orm import mapperlib
@@ -42,20 +42,20 @@ class FakeLock(object):
def run1():
for i in range(50):
- print "T1", thread.get_ident()
+ print("T1", _thread.get_ident())
class_mapper(T1)
time.sleep(.05)
def run2():
for i in range(50):
- print "T2", thread.get_ident()
+ print("T2", _thread.get_ident())
class_mapper(T2)
time.sleep(.057)
def run3():
for i in range(50):
def foo():
- print "FOO", thread.get_ident()
+ print("FOO", _thread.get_ident())
class Foo(object):pass
mapper(Foo, t3)
class_mapper(Foo).compile()
@@ -64,12 +64,12 @@ def run3():
mapper(T1, t1, properties={'t2':relationship(T2, backref="t1")})
mapper(T2, t2)
-print "START"
+print("START")
for j in range(0, 5):
- thread.start_new_thread(run1, ())
- thread.start_new_thread(run2, ())
- thread.start_new_thread(run3, ())
- thread.start_new_thread(run3, ())
- thread.start_new_thread(run3, ())
-print "WAIT"
+ _thread.start_new_thread(run1, ())
+ _thread.start_new_thread(run2, ())
+ _thread.start_new_thread(run3, ())
+ _thread.start_new_thread(run3, ())
+ _thread.start_new_thread(run3, ())
+print("WAIT")
time.sleep(5)