Commit f1ac4eb7 authored by Marc-André Lemburg's avatar Marc-André Lemburg

Updated to pybench 2.0.

See svn.python.org/external/pybench-2.0 for the original import of that
version.

Note that platform.py was not copied over from pybench-2.0 since
it is already part of Python 2.5.
parent 5131a4e5
...@@ -2,7 +2,7 @@ from pybench import Test ...@@ -2,7 +2,7 @@ from pybench import Test
class SimpleIntegerArithmetic(Test): class SimpleIntegerArithmetic(Test):
version = 0.3 version = 2.0
operations = 5 * (3 + 5 + 5 + 3 + 3 + 3) operations = 5 * (3 + 5 + 5 + 3 + 3 + 3)
rounds = 120000 rounds = 120000
...@@ -157,9 +157,9 @@ class SimpleIntegerArithmetic(Test): ...@@ -157,9 +157,9 @@ class SimpleIntegerArithmetic(Test):
class SimpleFloatArithmetic(Test): class SimpleFloatArithmetic(Test):
version = 0.3 version = 2.0
operations = 5 * (3 + 5 + 5 + 3 + 3 + 3) operations = 5 * (3 + 5 + 5 + 3 + 3 + 3)
rounds = 100000 rounds = 120000
def test(self): def test(self):
...@@ -312,7 +312,7 @@ class SimpleFloatArithmetic(Test): ...@@ -312,7 +312,7 @@ class SimpleFloatArithmetic(Test):
class SimpleIntFloatArithmetic(Test): class SimpleIntFloatArithmetic(Test):
version = 0.3 version = 2.0
operations = 5 * (3 + 5 + 5 + 3 + 3 + 3) operations = 5 * (3 + 5 + 5 + 3 + 3 + 3)
rounds = 120000 rounds = 120000
...@@ -468,9 +468,9 @@ class SimpleIntFloatArithmetic(Test): ...@@ -468,9 +468,9 @@ class SimpleIntFloatArithmetic(Test):
class SimpleLongArithmetic(Test): class SimpleLongArithmetic(Test):
version = 0.3 version = 2.0
operations = 5 * (3 + 5 + 5 + 3 + 3 + 3) operations = 5 * (3 + 5 + 5 + 3 + 3 + 3)
rounds = 30000 rounds = 60000
def test(self): def test(self):
...@@ -623,9 +623,9 @@ class SimpleLongArithmetic(Test): ...@@ -623,9 +623,9 @@ class SimpleLongArithmetic(Test):
class SimpleComplexArithmetic(Test): class SimpleComplexArithmetic(Test):
version = 0.3 version = 2.0
operations = 5 * (3 + 5 + 5 + 3 + 3 + 3) operations = 5 * (3 + 5 + 5 + 3 + 3 + 3)
rounds = 40000 rounds = 80000
def test(self): def test(self):
......
...@@ -2,7 +2,7 @@ from pybench import Test ...@@ -2,7 +2,7 @@ from pybench import Test
class PythonFunctionCalls(Test): class PythonFunctionCalls(Test):
version = 0.3 version = 2.0
operations = 5*(1+4+4+2) operations = 5*(1+4+4+2)
rounds = 60000 rounds = 60000
...@@ -111,9 +111,9 @@ class PythonFunctionCalls(Test): ...@@ -111,9 +111,9 @@ class PythonFunctionCalls(Test):
class BuiltinFunctionCalls(Test): class BuiltinFunctionCalls(Test):
version = 0.4 version = 2.0
operations = 5*(2+5+5+5) operations = 5*(2+5+5+5)
rounds = 30000 rounds = 60000
def test(self): def test(self):
...@@ -232,9 +232,9 @@ class BuiltinFunctionCalls(Test): ...@@ -232,9 +232,9 @@ class BuiltinFunctionCalls(Test):
class PythonMethodCalls(Test): class PythonMethodCalls(Test):
version = 0.3 version = 2.0
operations = 5*(6 + 5 + 4) operations = 5*(6 + 5 + 4)
rounds = 20000 rounds = 30000
def test(self): def test(self):
...@@ -374,9 +374,9 @@ class PythonMethodCalls(Test): ...@@ -374,9 +374,9 @@ class PythonMethodCalls(Test):
class Recursion(Test): class Recursion(Test):
version = 0.3 version = 2.0
operations = 5 operations = 5
rounds = 50000 rounds = 100000
def test(self): def test(self):
...@@ -407,3 +407,98 @@ class Recursion(Test): ...@@ -407,3 +407,98 @@ class Recursion(Test):
for i in xrange(self.rounds): for i in xrange(self.rounds):
pass pass
### Test to make Fredrik happy...
if __name__ == '__main__':
import timeit
if 0:
timeit.TestClass = PythonFunctionCalls
timeit.main(['-s', 'test = TestClass(); test.rounds = 1000',
'test.test()'])
else:
setup = """\
global f,f1,g,h
# define functions
def f():
pass
def f1(x):
pass
def g(a,b,c):
return a,b,c
def h(a,b,c,d=1,e=2,f=3):
return d,e,f
i = 1
"""
test = """\
f()
f1(i)
f1(i)
f1(i)
f1(i)
g(i,i,i)
g(i,i,i)
g(i,i,i)
g(i,i,i)
h(i,i,3,i,i)
h(i,i,i,2,i,3)
f()
f1(i)
f1(i)
f1(i)
f1(i)
g(i,i,i)
g(i,i,i)
g(i,i,i)
g(i,i,i)
h(i,i,3,i,i)
h(i,i,i,2,i,3)
f()
f1(i)
f1(i)
f1(i)
f1(i)
g(i,i,i)
g(i,i,i)
g(i,i,i)
g(i,i,i)
h(i,i,3,i,i)
h(i,i,i,2,i,3)
f()
f1(i)
f1(i)
f1(i)
f1(i)
g(i,i,i)
g(i,i,i)
g(i,i,i)
g(i,i,i)
h(i,i,3,i,i)
h(i,i,i,2,i,3)
f()
f1(i)
f1(i)
f1(i)
f1(i)
g(i,i,i)
g(i,i,i)
g(i,i,i)
g(i,i,i)
h(i,i,3,i,i)
h(i,i,i,2,i,3)
"""
timeit.main(['-s', setup,
test])
...@@ -358,7 +358,7 @@ class Application: ...@@ -358,7 +358,7 @@ class Application:
except self.InternalError: except self.InternalError:
print print
print '* Internal Error' print '* Internal Error (use --debug to display the traceback)'
if self.debug: if self.debug:
print print
traceback.print_exc(20, sys.stdout) traceback.print_exc(20, sys.stdout)
......
...@@ -2,7 +2,7 @@ from pybench import Test ...@@ -2,7 +2,7 @@ from pybench import Test
class IfThenElse(Test): class IfThenElse(Test):
version = 0.31 version = 2.0
operations = 30*3 # hard to say... operations = 30*3 # hard to say...
rounds = 150000 rounds = 150000
...@@ -469,9 +469,9 @@ class IfThenElse(Test): ...@@ -469,9 +469,9 @@ class IfThenElse(Test):
class NestedForLoops(Test): class NestedForLoops(Test):
version = 0.3 version = 2.0
operations = 1000*10*5 operations = 1000*10*5
rounds = 150 rounds = 300
def test(self): def test(self):
...@@ -494,9 +494,9 @@ class NestedForLoops(Test): ...@@ -494,9 +494,9 @@ class NestedForLoops(Test):
class ForLoops(Test): class ForLoops(Test):
version = 0.1 version = 2.0
operations = 5 * 5 operations = 5 * 5
rounds = 8000 rounds = 10000
def test(self): def test(self):
......
...@@ -2,9 +2,9 @@ from pybench import Test ...@@ -2,9 +2,9 @@ from pybench import Test
class DictCreation(Test): class DictCreation(Test):
version = 0.3 version = 2.0
operations = 5*(5 + 5) operations = 5*(5 + 5)
rounds = 60000 rounds = 80000
def test(self): def test(self):
...@@ -77,7 +77,7 @@ class DictCreation(Test): ...@@ -77,7 +77,7 @@ class DictCreation(Test):
class DictWithStringKeys(Test): class DictWithStringKeys(Test):
version = 0.1 version = 2.0
operations = 5*(6 + 6) operations = 5*(6 + 6)
rounds = 200000 rounds = 200000
...@@ -166,9 +166,9 @@ class DictWithStringKeys(Test): ...@@ -166,9 +166,9 @@ class DictWithStringKeys(Test):
class DictWithFloatKeys(Test): class DictWithFloatKeys(Test):
version = 0.1 version = 2.0
operations = 5*(6 + 6) operations = 5*(6 + 6)
rounds = 200000 rounds = 150000
def test(self): def test(self):
...@@ -255,7 +255,7 @@ class DictWithFloatKeys(Test): ...@@ -255,7 +255,7 @@ class DictWithFloatKeys(Test):
class DictWithIntegerKeys(Test): class DictWithIntegerKeys(Test):
version = 0.1 version = 2.0
operations = 5*(6 + 6) operations = 5*(6 + 6)
rounds = 200000 rounds = 200000
...@@ -344,13 +344,14 @@ class DictWithIntegerKeys(Test): ...@@ -344,13 +344,14 @@ class DictWithIntegerKeys(Test):
class SimpleDictManipulation(Test): class SimpleDictManipulation(Test):
version = 0.3 version = 2.0
operations = 5*(6 + 6 + 6 + 6) operations = 5*(6 + 6 + 6 + 6)
rounds = 50000 rounds = 100000
def test(self): def test(self):
d = {} d = {}
has_key = d.has_key
for i in xrange(self.rounds): for i in xrange(self.rounds):
...@@ -368,12 +369,12 @@ class SimpleDictManipulation(Test): ...@@ -368,12 +369,12 @@ class SimpleDictManipulation(Test):
x = d[4] x = d[4]
x = d[5] x = d[5]
d.has_key(0) has_key(0)
d.has_key(2) has_key(2)
d.has_key(4) has_key(4)
d.has_key(6) has_key(6)
d.has_key(8) has_key(8)
d.has_key(10) has_key(10)
del d[0] del d[0]
del d[1] del d[1]
...@@ -396,12 +397,12 @@ class SimpleDictManipulation(Test): ...@@ -396,12 +397,12 @@ class SimpleDictManipulation(Test):
x = d[4] x = d[4]
x = d[5] x = d[5]
d.has_key(0) has_key(0)
d.has_key(2) has_key(2)
d.has_key(4) has_key(4)
d.has_key(6) has_key(6)
d.has_key(8) has_key(8)
d.has_key(10) has_key(10)
del d[0] del d[0]
del d[1] del d[1]
...@@ -424,12 +425,12 @@ class SimpleDictManipulation(Test): ...@@ -424,12 +425,12 @@ class SimpleDictManipulation(Test):
x = d[4] x = d[4]
x = d[5] x = d[5]
d.has_key(0) has_key(0)
d.has_key(2) has_key(2)
d.has_key(4) has_key(4)
d.has_key(6) has_key(6)
d.has_key(8) has_key(8)
d.has_key(10) has_key(10)
del d[0] del d[0]
del d[1] del d[1]
...@@ -452,12 +453,12 @@ class SimpleDictManipulation(Test): ...@@ -452,12 +453,12 @@ class SimpleDictManipulation(Test):
x = d[4] x = d[4]
x = d[5] x = d[5]
d.has_key(0) has_key(0)
d.has_key(2) has_key(2)
d.has_key(4) has_key(4)
d.has_key(6) has_key(6)
d.has_key(8) has_key(8)
d.has_key(10) has_key(10)
del d[0] del d[0]
del d[1] del d[1]
...@@ -480,12 +481,12 @@ class SimpleDictManipulation(Test): ...@@ -480,12 +481,12 @@ class SimpleDictManipulation(Test):
x = d[4] x = d[4]
x = d[5] x = d[5]
d.has_key(0) has_key(0)
d.has_key(2) has_key(2)
d.has_key(4) has_key(4)
d.has_key(6) has_key(6)
d.has_key(8) has_key(8)
d.has_key(10) has_key(10)
del d[0] del d[0]
del d[1] del d[1]
...@@ -497,6 +498,7 @@ class SimpleDictManipulation(Test): ...@@ -497,6 +498,7 @@ class SimpleDictManipulation(Test):
def calibrate(self): def calibrate(self):
d = {} d = {}
has_key = d.has_key
for i in xrange(self.rounds): for i in xrange(self.rounds):
pass pass
...@@ -2,9 +2,9 @@ from pybench import Test ...@@ -2,9 +2,9 @@ from pybench import Test
class TryRaiseExcept(Test): class TryRaiseExcept(Test):
version = 0.1 version = 2.0
operations = 2 + 3 operations = 2 + 3 + 3
rounds = 60000 rounds = 80000
def test(self): def test(self):
...@@ -31,6 +31,18 @@ class TryRaiseExcept(Test): ...@@ -31,6 +31,18 @@ class TryRaiseExcept(Test):
raise error,"something" raise error,"something"
except: except:
pass pass
try:
raise error("something")
except:
pass
try:
raise error("something")
except:
pass
try:
raise error("something")
except:
pass
def calibrate(self): def calibrate(self):
...@@ -42,9 +54,9 @@ class TryRaiseExcept(Test): ...@@ -42,9 +54,9 @@ class TryRaiseExcept(Test):
class TryExcept(Test): class TryExcept(Test):
version = 0.1 version = 2.0
operations = 15 * 10 operations = 15 * 10
rounds = 200000 rounds = 150000
def test(self): def test(self):
...@@ -677,3 +689,11 @@ class TryExcept(Test): ...@@ -677,3 +689,11 @@ class TryExcept(Test):
for i in xrange(self.rounds): for i in xrange(self.rounds):
pass pass
### Test to make Fredrik happy...
if __name__ == '__main__':
import timeit
timeit.TestClass = TryRaiseExcept
timeit.main(['-s', 'test = TestClass(); test.rounds = 1000',
'test.test()'])
...@@ -6,9 +6,9 @@ import package.submodule ...@@ -6,9 +6,9 @@ import package.submodule
class SecondImport(Test): class SecondImport(Test):
version = 0.1 version = 2.0
operations = 5 * 5 operations = 5 * 5
rounds = 20000 rounds = 40000
def test(self): def test(self):
...@@ -51,9 +51,9 @@ class SecondImport(Test): ...@@ -51,9 +51,9 @@ class SecondImport(Test):
class SecondPackageImport(Test): class SecondPackageImport(Test):
version = 0.1 version = 2.0
operations = 5 * 5 operations = 5 * 5
rounds = 20000 rounds = 40000
def test(self): def test(self):
...@@ -95,9 +95,9 @@ class SecondPackageImport(Test): ...@@ -95,9 +95,9 @@ class SecondPackageImport(Test):
class SecondSubmoduleImport(Test): class SecondSubmoduleImport(Test):
version = 0.1 version = 2.0
operations = 5 * 5 operations = 5 * 5
rounds = 20000 rounds = 40000
def test(self): def test(self):
......
...@@ -2,9 +2,9 @@ from pybench import Test ...@@ -2,9 +2,9 @@ from pybench import Test
class CreateInstances(Test): class CreateInstances(Test):
version = 0.2 version = 2.0
operations = 3 + 7 + 4 operations = 3 + 7 + 4
rounds = 60000 rounds = 80000
def test(self): def test(self):
......
...@@ -2,22 +2,23 @@ from pybench import Test ...@@ -2,22 +2,23 @@ from pybench import Test
class SimpleListManipulation(Test): class SimpleListManipulation(Test):
version = 0.3 version = 2.0
operations = 5* (6 + 6 + 6) operations = 5* (6 + 6 + 6)
rounds = 60000 rounds = 130000
def test(self): def test(self):
l = [] l = []
append = l.append
for i in xrange(self.rounds): for i in xrange(self.rounds):
l.append(2) append(2)
l.append(3) append(3)
l.append(4) append(4)
l.append(2) append(2)
l.append(3) append(3)
l.append(4) append(4)
l[0] = 3 l[0] = 3
l[1] = 4 l[1] = 4
...@@ -33,12 +34,12 @@ class SimpleListManipulation(Test): ...@@ -33,12 +34,12 @@ class SimpleListManipulation(Test):
x = l[4] x = l[4]
x = l[5] x = l[5]
l.append(2) append(2)
l.append(3) append(3)
l.append(4) append(4)
l.append(2) append(2)
l.append(3) append(3)
l.append(4) append(4)
l[0] = 3 l[0] = 3
l[1] = 4 l[1] = 4
...@@ -54,12 +55,12 @@ class SimpleListManipulation(Test): ...@@ -54,12 +55,12 @@ class SimpleListManipulation(Test):
x = l[4] x = l[4]
x = l[5] x = l[5]
l.append(2) append(2)
l.append(3) append(3)
l.append(4) append(4)
l.append(2) append(2)
l.append(3) append(3)
l.append(4) append(4)
l[0] = 3 l[0] = 3
l[1] = 4 l[1] = 4
...@@ -75,12 +76,12 @@ class SimpleListManipulation(Test): ...@@ -75,12 +76,12 @@ class SimpleListManipulation(Test):
x = l[4] x = l[4]
x = l[5] x = l[5]
l.append(2) append(2)
l.append(3) append(3)
l.append(4) append(4)
l.append(2) append(2)
l.append(3) append(3)
l.append(4) append(4)
l[0] = 3 l[0] = 3
l[1] = 4 l[1] = 4
...@@ -96,12 +97,12 @@ class SimpleListManipulation(Test): ...@@ -96,12 +97,12 @@ class SimpleListManipulation(Test):
x = l[4] x = l[4]
x = l[5] x = l[5]
l.append(2) append(2)
l.append(3) append(3)
l.append(4) append(4)
l.append(2) append(2)
l.append(3) append(3)
l.append(4) append(4)
l[0] = 3 l[0] = 3
l[1] = 4 l[1] = 4
...@@ -124,15 +125,16 @@ class SimpleListManipulation(Test): ...@@ -124,15 +125,16 @@ class SimpleListManipulation(Test):
def calibrate(self): def calibrate(self):
l = [] l = []
append = l.append
for i in xrange(self.rounds): for i in xrange(self.rounds):
pass pass
class ListSlicing(Test): class ListSlicing(Test):
version = 0.4 version = 2.0
operations = 25*(3+1+2+1) operations = 25*(3+1+2+1)
rounds = 400 rounds = 800
def test(self): def test(self):
...@@ -141,7 +143,7 @@ class ListSlicing(Test): ...@@ -141,7 +143,7 @@ class ListSlicing(Test):
for i in xrange(self.rounds): for i in xrange(self.rounds):
l = range(100) l = n[:]
for j in r: for j in r:
...@@ -159,17 +161,14 @@ class ListSlicing(Test): ...@@ -159,17 +161,14 @@ class ListSlicing(Test):
r = range(25) r = range(25)
for i in xrange(self.rounds): for i in xrange(self.rounds):
l = range(100)
for j in r: for j in r:
pass pass
class SmallLists(Test): class SmallLists(Test):
version = 0.3 version = 2.0
operations = 5*(1+ 6 + 6 + 3 + 1) operations = 5*(1+ 6 + 6 + 3 + 1)
rounds = 60000 rounds = 80000
def test(self): def test(self):
...@@ -177,12 +176,13 @@ class SmallLists(Test): ...@@ -177,12 +176,13 @@ class SmallLists(Test):
l = [] l = []
l.append(2) append = l.append
l.append(3) append(2)
l.append(4) append(3)
l.append(2) append(4)
l.append(3) append(2)
l.append(4) append(3)
append(4)
l[0] = 3 l[0] = 3
l[1] = 4 l[1] = 4
...@@ -199,12 +199,13 @@ class SmallLists(Test): ...@@ -199,12 +199,13 @@ class SmallLists(Test):
l = [] l = []
l.append(2) append = l.append
l.append(3) append(2)
l.append(4) append(3)
l.append(2) append(4)
l.append(3) append(2)
l.append(4) append(3)
append(4)
l[0] = 3 l[0] = 3
l[1] = 4 l[1] = 4
...@@ -221,12 +222,13 @@ class SmallLists(Test): ...@@ -221,12 +222,13 @@ class SmallLists(Test):
l = [] l = []
l.append(2) append = l.append
l.append(3) append(2)
l.append(4) append(3)
l.append(2) append(4)
l.append(3) append(2)
l.append(4) append(3)
append(4)
l[0] = 3 l[0] = 3
l[1] = 4 l[1] = 4
...@@ -243,12 +245,13 @@ class SmallLists(Test): ...@@ -243,12 +245,13 @@ class SmallLists(Test):
l = [] l = []
l.append(2) append = l.append
l.append(3) append(2)
l.append(4) append(3)
l.append(2) append(4)
l.append(3) append(2)
l.append(4) append(3)
append(4)
l[0] = 3 l[0] = 3
l[1] = 4 l[1] = 4
...@@ -265,12 +268,13 @@ class SmallLists(Test): ...@@ -265,12 +268,13 @@ class SmallLists(Test):
l = [] l = []
l.append(2) append = l.append
l.append(3) append(2)
l.append(4) append(3)
l.append(2) append(4)
l.append(3) append(2)
l.append(4) append(3)
append(4)
l[0] = 3 l[0] = 3
l[1] = 4 l[1] = 4
...@@ -288,4 +292,4 @@ class SmallLists(Test): ...@@ -288,4 +292,4 @@ class SmallLists(Test):
def calibrate(self): def calibrate(self):
for i in xrange(self.rounds): for i in xrange(self.rounds):
l = [] pass
...@@ -2,7 +2,7 @@ from pybench import Test ...@@ -2,7 +2,7 @@ from pybench import Test
class SpecialClassAttribute(Test): class SpecialClassAttribute(Test):
version = 0.3 version = 2.0
operations = 5*(12 + 12) operations = 5*(12 + 12)
rounds = 100000 rounds = 100000
...@@ -183,7 +183,7 @@ class SpecialClassAttribute(Test): ...@@ -183,7 +183,7 @@ class SpecialClassAttribute(Test):
class NormalClassAttribute(Test): class NormalClassAttribute(Test):
version = 0.3 version = 2.0
operations = 5*(12 + 12) operations = 5*(12 + 12)
rounds = 100000 rounds = 100000
...@@ -369,7 +369,7 @@ class NormalClassAttribute(Test): ...@@ -369,7 +369,7 @@ class NormalClassAttribute(Test):
class SpecialInstanceAttribute(Test): class SpecialInstanceAttribute(Test):
version = 0.3 version = 2.0
operations = 5*(12 + 12) operations = 5*(12 + 12)
rounds = 100000 rounds = 100000
...@@ -557,7 +557,7 @@ class SpecialInstanceAttribute(Test): ...@@ -557,7 +557,7 @@ class SpecialInstanceAttribute(Test):
class NormalInstanceAttribute(Test): class NormalInstanceAttribute(Test):
version = 0.3 version = 2.0
operations = 5*(12 + 12) operations = 5*(12 + 12)
rounds = 100000 rounds = 100000
...@@ -745,7 +745,7 @@ class NormalInstanceAttribute(Test): ...@@ -745,7 +745,7 @@ class NormalInstanceAttribute(Test):
class BuiltinMethodLookup(Test): class BuiltinMethodLookup(Test):
version = 0.3 version = 2.0
operations = 5*(3*5 + 3*5) operations = 5*(3*5 + 3*5)
rounds = 70000 rounds = 70000
......
from pybench import Test from pybench import Test
# Check for new-style class support:
try:
class c(object):
pass
except NameError:
raise ImportError
###
class CreateNewInstances(Test): class CreateNewInstances(Test):
version = 0.1 version = 2.0
operations = 3 + 7 + 4 operations = 3 + 7 + 4
rounds = 60000 rounds = 60000
......
...@@ -2,7 +2,7 @@ from pybench import Test ...@@ -2,7 +2,7 @@ from pybench import Test
class CompareIntegers(Test): class CompareIntegers(Test):
version = 0.1 version = 2.0
operations = 30 * 5 operations = 30 * 5
rounds = 120000 rounds = 120000
...@@ -198,9 +198,9 @@ class CompareIntegers(Test): ...@@ -198,9 +198,9 @@ class CompareIntegers(Test):
class CompareFloats(Test): class CompareFloats(Test):
version = 0.1 version = 2.0
operations = 30 * 5 operations = 30 * 5
rounds = 60000 rounds = 80000
def test(self): def test(self):
...@@ -394,7 +394,7 @@ class CompareFloats(Test): ...@@ -394,7 +394,7 @@ class CompareFloats(Test):
class CompareFloatsIntegers(Test): class CompareFloatsIntegers(Test):
version = 0.1 version = 2.0
operations = 30 * 5 operations = 30 * 5
rounds = 60000 rounds = 60000
...@@ -590,9 +590,9 @@ class CompareFloatsIntegers(Test): ...@@ -590,9 +590,9 @@ class CompareFloatsIntegers(Test):
class CompareLongs(Test): class CompareLongs(Test):
version = 0.1 version = 2.0
operations = 30 * 5 operations = 30 * 5
rounds = 60000 rounds = 70000
def test(self): def test(self):
......
This diff is collapsed.
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
# Defaults # Defaults
Number_of_rounds = 10 Number_of_rounds = 10
Warp_factor = 20 Warp_factor = 10
# Import tests # Import tests
from Arithmetic import * from Arithmetic import *
...@@ -24,8 +24,8 @@ from Lookups import * ...@@ -24,8 +24,8 @@ from Lookups import *
from Instances import * from Instances import *
try: try:
from NewInstances import * from NewInstances import *
except: except ImportError:
print "Cannot test new-style objects" pass
from Lists import * from Lists import *
from Tuples import * from Tuples import *
from Dict import * from Dict import *
......
...@@ -3,9 +3,9 @@ from string import join ...@@ -3,9 +3,9 @@ from string import join
class ConcatStrings(Test): class ConcatStrings(Test):
version = 0.1 version = 2.0
operations = 10 * 5 operations = 10 * 5
rounds = 60000 rounds = 100000
def test(self): def test(self):
...@@ -85,7 +85,7 @@ class ConcatStrings(Test): ...@@ -85,7 +85,7 @@ class ConcatStrings(Test):
class CompareStrings(Test): class CompareStrings(Test):
version = 0.2 version = 2.0
operations = 10 * 5 operations = 10 * 5
rounds = 200000 rounds = 200000
...@@ -167,9 +167,9 @@ class CompareStrings(Test): ...@@ -167,9 +167,9 @@ class CompareStrings(Test):
class CompareInternedStrings(Test): class CompareInternedStrings(Test):
version = 0.1 version = 2.0
operations = 10 * 5 operations = 10 * 5
rounds = 200000 rounds = 300000
def test(self): def test(self):
...@@ -249,9 +249,9 @@ class CompareInternedStrings(Test): ...@@ -249,9 +249,9 @@ class CompareInternedStrings(Test):
class CreateStringsWithConcat(Test): class CreateStringsWithConcat(Test):
version = 0.1 version = 2.0
operations = 10 * 5 operations = 10 * 5
rounds = 80000 rounds = 200000
def test(self): def test(self):
...@@ -324,9 +324,9 @@ class CreateStringsWithConcat(Test): ...@@ -324,9 +324,9 @@ class CreateStringsWithConcat(Test):
class StringSlicing(Test): class StringSlicing(Test):
version = 0.1 version = 2.0
operations = 5 * 7 operations = 5 * 7
rounds = 100000 rounds = 160000
def test(self): def test(self):
...@@ -387,7 +387,7 @@ if hasattr('', 'lower'): ...@@ -387,7 +387,7 @@ if hasattr('', 'lower'):
class StringMappings(Test): class StringMappings(Test):
version = 0.1 version = 2.0
operations = 3 * (5 + 4 + 2 + 1) operations = 3 * (5 + 4 + 2 + 1)
rounds = 70000 rounds = 70000
...@@ -460,9 +460,9 @@ if hasattr('', 'lower'): ...@@ -460,9 +460,9 @@ if hasattr('', 'lower'):
class StringPredicates(Test): class StringPredicates(Test):
version = 0.1 version = 2.0
operations = 10 * 7 operations = 10 * 7
rounds = 80000 rounds = 100000
def test(self): def test(self):
......
...@@ -2,18 +2,17 @@ from pybench import Test ...@@ -2,18 +2,17 @@ from pybench import Test
class TupleSlicing(Test): class TupleSlicing(Test):
version = 0.31 version = 2.0
operations = 3 * 25 * 10 * 7 operations = 3 * 25 * 10 * 7
rounds = 400 rounds = 500
def test(self): def test(self):
r = range(25) r = range(25)
t = tuple(range(100))
for i in xrange(self.rounds): for i in xrange(self.rounds):
t = tuple(range(100))
for j in r: for j in r:
m = t[50:] m = t[50:]
...@@ -259,20 +258,17 @@ class TupleSlicing(Test): ...@@ -259,20 +258,17 @@ class TupleSlicing(Test):
def calibrate(self): def calibrate(self):
r = range(25) r = range(25)
t = tuple(range(100))
for i in xrange(self.rounds): for i in xrange(self.rounds):
t = tuple(range(100))
for j in r: for j in r:
pass pass
class SmallTuples(Test): class SmallTuples(Test):
version = 0.3 version = 2.0
operations = 5*(1 + 3 + 6 + 2) operations = 5*(1 + 3 + 6 + 2)
rounds = 80000 rounds = 90000
def test(self): def test(self):
......
...@@ -8,7 +8,7 @@ from string import join ...@@ -8,7 +8,7 @@ from string import join
class ConcatUnicode(Test): class ConcatUnicode(Test):
version = 0.1 version = 2.0
operations = 10 * 5 operations = 10 * 5
rounds = 60000 rounds = 60000
...@@ -90,7 +90,7 @@ class ConcatUnicode(Test): ...@@ -90,7 +90,7 @@ class ConcatUnicode(Test):
class CompareUnicode(Test): class CompareUnicode(Test):
version = 0.1 version = 2.0
operations = 10 * 5 operations = 10 * 5
rounds = 150000 rounds = 150000
...@@ -172,7 +172,7 @@ class CompareUnicode(Test): ...@@ -172,7 +172,7 @@ class CompareUnicode(Test):
class CreateUnicodeWithConcat(Test): class CreateUnicodeWithConcat(Test):
version = 0.1 version = 2.0
operations = 10 * 5 operations = 10 * 5
rounds = 80000 rounds = 80000
...@@ -247,9 +247,9 @@ class CreateUnicodeWithConcat(Test): ...@@ -247,9 +247,9 @@ class CreateUnicodeWithConcat(Test):
class UnicodeSlicing(Test): class UnicodeSlicing(Test):
version = 0.1 version = 2.0
operations = 5 * 7 operations = 5 * 7
rounds = 100000 rounds = 140000
def test(self): def test(self):
...@@ -308,7 +308,7 @@ class UnicodeSlicing(Test): ...@@ -308,7 +308,7 @@ class UnicodeSlicing(Test):
class UnicodeMappings(Test): class UnicodeMappings(Test):
version = 0.1 version = 2.0
operations = 3 * (5 + 4 + 2 + 1) operations = 3 * (5 + 4 + 2 + 1)
rounds = 10000 rounds = 10000
...@@ -381,9 +381,9 @@ class UnicodeMappings(Test): ...@@ -381,9 +381,9 @@ class UnicodeMappings(Test):
class UnicodePredicates(Test): class UnicodePredicates(Test):
version = 0.1 version = 2.0
operations = 5 * 9 operations = 5 * 9
rounds = 100000 rounds = 120000
def test(self): def test(self):
...@@ -458,7 +458,7 @@ except ImportError: ...@@ -458,7 +458,7 @@ except ImportError:
else: else:
class UnicodeProperties(Test): class UnicodeProperties(Test):
version = 0.1 version = 2.0
operations = 5 * 8 operations = 5 * 8
rounds = 100000 rounds = 100000
......
#!/usr/bin/env python
""" clockres - calculates the resolution in seconds of a given timer.
Copyright (c) 2006, Marc-Andre Lemburg (mal@egenix.com). See the
documentation for further information on copyrights, or contact
the author. All Rights Reserved.
"""
import time
TEST_TIME = 1.0
def clockres(timer):
d = {}
wallclock = time.time
start = wallclock()
stop = wallclock() + TEST_TIME
spin_loops = range(1000)
while 1:
now = wallclock()
if now >= stop:
break
for i in spin_loops:
d[timer()] = 1
values = d.keys()
values.sort()
min_diff = TEST_TIME
for i in range(len(values) - 1):
diff = values[i+1] - values[i]
if diff < min_diff:
min_diff = diff
return min_diff
if __name__ == '__main__':
print 'Clock resolution of various timer implementations:'
print 'time.clock: %10.3fus' % (clockres(time.clock) * 1e6)
print 'time.time: %10.3fus' % (clockres(time.time) * 1e6)
try:
import systimes
print 'systimes.processtime: %10.3fus' % (clockres(systimes.processtime) * 1e6)
except ImportError:
pass
This diff is collapsed.
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
platforms. platforms.
If no supported timing methods based on process time can be found, If no supported timing methods based on process time can be found,
the module reverts to the highest resolution wall-time timer the module reverts to the highest resolution wall-clock timer
instead. The system time part will then always be 0.0. instead. The system time part will then always be 0.0.
The module exports one public API: The module exports one public API:
...@@ -52,8 +52,8 @@ USE_CTYPES_GETPROCESSTIMES = 'cytpes GetProcessTimes() wrapper' ...@@ -52,8 +52,8 @@ USE_CTYPES_GETPROCESSTIMES = 'cytpes GetProcessTimes() wrapper'
USE_WIN32PROCESS_GETPROCESSTIMES = 'win32process.GetProcessTimes()' USE_WIN32PROCESS_GETPROCESSTIMES = 'win32process.GetProcessTimes()'
USE_RESOURCE_GETRUSAGE = 'resource.getrusage()' USE_RESOURCE_GETRUSAGE = 'resource.getrusage()'
USE_PROCESS_TIME_CLOCK = 'time.clock() (process time)' USE_PROCESS_TIME_CLOCK = 'time.clock() (process time)'
USE_WALL_TIME_CLOCK = 'time.clock() (wall-time)' USE_WALL_TIME_CLOCK = 'time.clock() (wall-clock)'
USE_WALL_TIME_TIME = 'time.time() (wall-time)' USE_WALL_TIME_TIME = 'time.time() (wall-clock)'
if sys.platform[:3] == 'win': if sys.platform[:3] == 'win':
# Windows platform # Windows platform
...@@ -63,7 +63,7 @@ if sys.platform[:3] == 'win': ...@@ -63,7 +63,7 @@ if sys.platform[:3] == 'win':
try: try:
import ctypes import ctypes
except ImportError: except ImportError:
# Use the wall-time implementation time.clock(), since this # Use the wall-clock implementation time.clock(), since this
# is the highest resolution clock available on Windows # is the highest resolution clock available on Windows
SYSTIMES_IMPLEMENTATION = USE_WALL_TIME_CLOCK SYSTIMES_IMPLEMENTATION = USE_WALL_TIME_CLOCK
else: else:
...@@ -91,7 +91,7 @@ if SYSTIMES_IMPLEMENTATION is None: ...@@ -91,7 +91,7 @@ if SYSTIMES_IMPLEMENTATION is None:
# time) # time)
SYSTIMES_IMPLEMENTATION = USE_PROCESS_TIME_CLOCK SYSTIMES_IMPLEMENTATION = USE_PROCESS_TIME_CLOCK
else: else:
# Use wall-time implementation time.time() since this provides # Use wall-clock implementation time.time() since this provides
# the highest resolution clock on most systems # the highest resolution clock on most systems
SYSTIMES_IMPLEMENTATION = USE_WALL_TIME_TIME SYSTIMES_IMPLEMENTATION = USE_WALL_TIME_TIME
...@@ -103,24 +103,27 @@ def getrusage_systimes(): ...@@ -103,24 +103,27 @@ def getrusage_systimes():
def process_time_clock_systimes(): def process_time_clock_systimes():
return (time.clock(), 0.0) return (time.clock(), 0.0)
def wall_time_clock_systimes(): def wall_clock_clock_systimes():
return (time.clock(), 0.0) return (time.clock(), 0.0)
def wall_time_time_systimes(): def wall_clock_time_systimes():
return (time.time(), 0.0) return (time.time(), 0.0)
# Number of clock ticks per second for the values returned # Number of clock ticks per second for the values returned
# by GetProcessTimes() on Windows. # by GetProcessTimes() on Windows.
# #
# Note: Ticks returned by GetProcessTimes() are micro-seconds on # Note: Ticks returned by GetProcessTimes() are 100ns intervals on
# Windows XP (though the docs say 100ns intervals) # Windows XP. However, the process times are only updated with every
WIN32_PROCESS_TIMES_TICKS_PER_SECOND = 10e6 # clock tick and the frequency of these is somewhat lower: depending
# on the OS version between 10ms and 15ms. Even worse, the process
# time seems to be allocated to process currently running when the
# clock interrupt arrives, ie. it is possible that the current time
# slice gets accounted to a different process.
WIN32_PROCESS_TIMES_TICKS_PER_SECOND = 1e7
def win32process_getprocesstimes_systimes(): def win32process_getprocesstimes_systimes():
d = win32process.GetProcessTimes(win32process.GetCurrentProcess()) d = win32process.GetProcessTimes(win32process.GetCurrentProcess())
# Note: I'm not sure whether KernelTime on Windows is the same as
# system time on Unix - I've yet to see a non-zero value for
# KernelTime on Windows.
return (d['UserTime'] / WIN32_PROCESS_TIMES_TICKS_PER_SECOND, return (d['UserTime'] / WIN32_PROCESS_TIMES_TICKS_PER_SECOND,
d['KernelTime'] / WIN32_PROCESS_TIMES_TICKS_PER_SECOND) d['KernelTime'] / WIN32_PROCESS_TIMES_TICKS_PER_SECOND)
...@@ -149,10 +152,10 @@ elif SYSTIMES_IMPLEMENTATION is USE_PROCESS_TIME_CLOCK: ...@@ -149,10 +152,10 @@ elif SYSTIMES_IMPLEMENTATION is USE_PROCESS_TIME_CLOCK:
systimes = process_time_clock_systimes systimes = process_time_clock_systimes
elif SYSTIMES_IMPLEMENTATION is USE_WALL_TIME_CLOCK: elif SYSTIMES_IMPLEMENTATION is USE_WALL_TIME_CLOCK:
systimes = wall_time_clock_systimes systimes = wall_clock_clock_systimes
elif SYSTIMES_IMPLEMENTATION is USE_WALL_TIME_TIME: elif SYSTIMES_IMPLEMENTATION is USE_WALL_TIME_TIME:
systimes = wall_time_time_systimes systimes = wall_clock_time_systimes
elif SYSTIMES_IMPLEMENTATION is USE_WIN32PROCESS_GETPROCESSTIMES: elif SYSTIMES_IMPLEMENTATION is USE_WIN32PROCESS_GETPROCESSTIMES:
systimes = win32process_getprocesstimes_systimes systimes = win32process_getprocesstimes_systimes
...@@ -163,6 +166,17 @@ elif SYSTIMES_IMPLEMENTATION is USE_CTYPES_GETPROCESSTIMES: ...@@ -163,6 +166,17 @@ elif SYSTIMES_IMPLEMENTATION is USE_CTYPES_GETPROCESSTIMES:
else: else:
raise TypeError('no suitable systimes() implementation found') raise TypeError('no suitable systimes() implementation found')
def processtime():
""" Return the total time spent on the process.
This is the sum of user and system time as returned by
systimes().
"""
user, system = systimes()
return user + system
### Testing ### Testing
def some_workload(): def some_workload():
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment