Commit 70f03984 authored by Marc-André Lemburg's avatar Marc-André Lemburg

Update pybench to version 2.0.

parent 7f36041d
This diff is collapsed.
from pybench import Test
class PythonFunctionCalls(Test):
version = 2.0
operations = 5*(1+4+4+2)
rounds = 60000
def test(self):
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
# do calls
for i in xrange(self.rounds):
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)
def calibrate(self):
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
# do calls
for i in xrange(self.rounds):
pass
###
class BuiltinFunctionCalls(Test):
version = 2.0
operations = 5*(2+5+5+5)
rounds = 60000
def test(self):
# localize functions
f0 = globals
f1 = hash
f2 = cmp
f3 = range
# do calls
for i in xrange(self.rounds):
f0()
f0()
f1(i)
f1(i)
f1(i)
f1(i)
f1(i)
f2(1,2)
f2(1,2)
f2(1,2)
f2(1,2)
f2(1,2)
f3(1,3,2)
f3(1,3,2)
f3(1,3,2)
f3(1,3,2)
f3(1,3,2)
f0()
f0()
f1(i)
f1(i)
f1(i)
f1(i)
f1(i)
f2(1,2)
f2(1,2)
f2(1,2)
f2(1,2)
f2(1,2)
f3(1,3,2)
f3(1,3,2)
f3(1,3,2)
f3(1,3,2)
f3(1,3,2)
f0()
f0()
f1(i)
f1(i)
f1(i)
f1(i)
f1(i)
f2(1,2)
f2(1,2)
f2(1,2)
f2(1,2)
f2(1,2)
f3(1,3,2)
f3(1,3,2)
f3(1,3,2)
f3(1,3,2)
f3(1,3,2)
f0()
f0()
f1(i)
f1(i)
f1(i)
f1(i)
f1(i)
f2(1,2)
f2(1,2)
f2(1,2)
f2(1,2)
f2(1,2)
f3(1,3,2)
f3(1,3,2)
f3(1,3,2)
f3(1,3,2)
f3(1,3,2)
f0()
f0()
f1(i)
f1(i)
f1(i)
f1(i)
f1(i)
f2(1,2)
f2(1,2)
f2(1,2)
f2(1,2)
f2(1,2)
f3(1,3,2)
f3(1,3,2)
f3(1,3,2)
f3(1,3,2)
f3(1,3,2)
def calibrate(self):
# localize functions
f0 = dir
f1 = hash
f2 = range
f3 = range
# do calls
for i in xrange(self.rounds):
pass
###
class PythonMethodCalls(Test):
version = 2.0
operations = 5*(6 + 5 + 4)
rounds = 30000
def test(self):
class c:
x = 2
s = 'string'
def f(self):
return self.x
def j(self,a,b):
self.y = a
self.t = b
return self.y
def k(self,a,b,c=3):
self.y = a
self.s = b
self.t = c
o = c()
for i in xrange(self.rounds):
o.f()
o.f()
o.f()
o.f()
o.f()
o.f()
o.j(i,i)
o.j(i,i)
o.j(i,2)
o.j(i,2)
o.j(2,2)
o.k(i,i)
o.k(i,2)
o.k(i,2,3)
o.k(i,i,c=4)
o.f()
o.f()
o.f()
o.f()
o.f()
o.f()
o.j(i,i)
o.j(i,i)
o.j(i,2)
o.j(i,2)
o.j(2,2)
o.k(i,i)
o.k(i,2)
o.k(i,2,3)
o.k(i,i,c=4)
o.f()
o.f()
o.f()
o.f()
o.f()
o.f()
o.j(i,i)
o.j(i,i)
o.j(i,2)
o.j(i,2)
o.j(2,2)
o.k(i,i)
o.k(i,2)
o.k(i,2,3)
o.k(i,i,c=4)
o.f()
o.f()
o.f()
o.f()
o.f()
o.f()
o.j(i,i)
o.j(i,i)
o.j(i,2)
o.j(i,2)
o.j(2,2)
o.k(i,i)
o.k(i,2)
o.k(i,2,3)
o.k(i,i,c=4)
o.f()
o.f()
o.f()
o.f()
o.f()
o.f()
o.j(i,i)
o.j(i,i)
o.j(i,2)
o.j(i,2)
o.j(2,2)
o.k(i,i)
o.k(i,2)
o.k(i,2,3)
o.k(i,i,c=4)
def calibrate(self):
class c:
x = 2
s = 'string'
def f(self):
return self.x
def j(self,a,b):
self.y = a
self.t = b
def k(self,a,b,c=3):
self.y = a
self.s = b
self.t = c
o = c
for i in xrange(self.rounds):
pass
###
class Recursion(Test):
version = 2.0
operations = 5
rounds = 100000
def test(self):
global f
def f(x):
if x > 1:
return f(x-1)
return 1
for i in xrange(self.rounds):
f(10)
f(10)
f(10)
f(10)
f(10)
def calibrate(self):
global f
def f(x):
if x > 0:
return f(x-1)
return 1
for i in xrange(self.rounds):
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])
This diff is collapsed.
This diff is collapsed.
from pybench import Test
class DictCreation(Test):
version = 2.0
operations = 5*(5 + 5)
rounds = 80000
def test(self):
for i in xrange(self.rounds):
d1 = {}
d2 = {}
d3 = {}
d4 = {}
d5 = {}
d1 = {1:2,3:4,5:6}
d2 = {2:3,4:5,6:7}
d3 = {3:4,5:6,7:8}
d4 = {4:5,6:7,8:9}
d5 = {6:7,8:9,10:11}
d1 = {}
d2 = {}
d3 = {}
d4 = {}
d5 = {}
d1 = {1:2,3:4,5:6}
d2 = {2:3,4:5,6:7}
d3 = {3:4,5:6,7:8}
d4 = {4:5,6:7,8:9}
d5 = {6:7,8:9,10:11}
d1 = {}
d2 = {}
d3 = {}
d4 = {}
d5 = {}
d1 = {1:2,3:4,5:6}
d2 = {2:3,4:5,6:7}
d3 = {3:4,5:6,7:8}
d4 = {4:5,6:7,8:9}
d5 = {6:7,8:9,10:11}
d1 = {}
d2 = {}
d3 = {}
d4 = {}
d5 = {}
d1 = {1:2,3:4,5:6}
d2 = {2:3,4:5,6:7}
d3 = {3:4,5:6,7:8}
d4 = {4:5,6:7,8:9}
d5 = {6:7,8:9,10:11}
d1 = {}
d2 = {}
d3 = {}
d4 = {}
d5 = {}
d1 = {1:2,3:4,5:6}
d2 = {2:3,4:5,6:7}
d3 = {3:4,5:6,7:8}
d4 = {4:5,6:7,8:9}
d5 = {6:7,8:9,10:11}
def calibrate(self):
for i in xrange(self.rounds):
pass
class DictWithStringKeys(Test):
version = 2.0
operations = 5*(6 + 6)
rounds = 200000
def test(self):
d = {}
for i in xrange(self.rounds):
d['abc'] = 1
d['def'] = 2
d['ghi'] = 3
d['jkl'] = 4
d['mno'] = 5
d['pqr'] = 6
d['abc']
d['def']
d['ghi']
d['jkl']
d['mno']
d['pqr']
d['abc'] = 1
d['def'] = 2
d['ghi'] = 3
d['jkl'] = 4
d['mno'] = 5
d['pqr'] = 6
d['abc']
d['def']
d['ghi']
d['jkl']
d['mno']
d['pqr']
d['abc'] = 1
d['def'] = 2
d['ghi'] = 3
d['jkl'] = 4
d['mno'] = 5
d['pqr'] = 6
d['abc']
d['def']
d['ghi']
d['jkl']
d['mno']
d['pqr']
d['abc'] = 1
d['def'] = 2
d['ghi'] = 3
d['jkl'] = 4
d['mno'] = 5
d['pqr'] = 6
d['abc']
d['def']
d['ghi']
d['jkl']
d['mno']
d['pqr']
d['abc'] = 1
d['def'] = 2
d['ghi'] = 3
d['jkl'] = 4
d['mno'] = 5
d['pqr'] = 6
d['abc']
d['def']
d['ghi']
d['jkl']
d['mno']
d['pqr']
def calibrate(self):
d = {}
for i in xrange(self.rounds):
pass
class DictWithFloatKeys(Test):
version = 2.0
operations = 5*(6 + 6)
rounds = 150000
def test(self):
d = {}
for i in xrange(self.rounds):
d[1.234] = 1
d[2.345] = 2
d[3.456] = 3
d[4.567] = 4
d[5.678] = 5
d[6.789] = 6
d[1.234]
d[2.345]
d[3.456]
d[4.567]
d[5.678]
d[6.789]
d[1.234] = 1
d[2.345] = 2
d[3.456] = 3
d[4.567] = 4
d[5.678] = 5
d[6.789] = 6
d[1.234]
d[2.345]
d[3.456]
d[4.567]
d[5.678]
d[6.789]
d[1.234] = 1
d[2.345] = 2
d[3.456] = 3
d[4.567] = 4
d[5.678] = 5
d[6.789] = 6
d[1.234]
d[2.345]
d[3.456]
d[4.567]
d[5.678]
d[6.789]
d[1.234] = 1
d[2.345] = 2
d[3.456] = 3
d[4.567] = 4
d[5.678] = 5
d[6.789] = 6
d[1.234]
d[2.345]
d[3.456]
d[4.567]
d[5.678]
d[6.789]
d[1.234] = 1
d[2.345] = 2
d[3.456] = 3
d[4.567] = 4
d[5.678] = 5
d[6.789] = 6
d[1.234]
d[2.345]
d[3.456]
d[4.567]
d[5.678]
d[6.789]
def calibrate(self):
d = {}
for i in xrange(self.rounds):
pass
class DictWithIntegerKeys(Test):
version = 2.0
operations = 5*(6 + 6)
rounds = 200000
def test(self):
d = {}
for i in xrange(self.rounds):
d[1] = 1
d[2] = 2
d[3] = 3
d[4] = 4
d[5] = 5
d[6] = 6
d[1]
d[2]
d[3]
d[4]
d[5]
d[6]
d[1] = 1
d[2] = 2
d[3] = 3
d[4] = 4
d[5] = 5
d[6] = 6
d[1]
d[2]
d[3]
d[4]
d[5]
d[6]
d[1] = 1
d[2] = 2
d[3] = 3
d[4] = 4
d[5] = 5
d[6] = 6
d[1]
d[2]
d[3]
d[4]
d[5]
d[6]
d[1] = 1
d[2] = 2
d[3] = 3
d[4] = 4
d[5] = 5
d[6] = 6
d[1]
d[2]
d[3]
d[4]
d[5]
d[6]
d[1] = 1
d[2] = 2
d[3] = 3
d[4] = 4
d[5] = 5
d[6] = 6
d[1]
d[2]
d[3]
d[4]
d[5]
d[6]
def calibrate(self):
d = {}
for i in xrange(self.rounds):
pass
class SimpleDictManipulation(Test):
version = 2.0
operations = 5*(6 + 6 + 6 + 6)
rounds = 100000
def test(self):
d = {}
has_key = d.has_key
for i in xrange(self.rounds):
d[0] = 3
d[1] = 4
d[2] = 5
d[3] = 3
d[4] = 4
d[5] = 5
x = d[0]
x = d[1]
x = d[2]
x = d[3]
x = d[4]
x = d[5]
has_key(0)
has_key(2)
has_key(4)
has_key(6)
has_key(8)
has_key(10)
del d[0]
del d[1]
del d[2]
del d[3]
del d[4]
del d[5]
d[0] = 3
d[1] = 4
d[2] = 5
d[3] = 3
d[4] = 4
d[5] = 5
x = d[0]
x = d[1]
x = d[2]
x = d[3]
x = d[4]
x = d[5]
has_key(0)
has_key(2)
has_key(4)
has_key(6)
has_key(8)
has_key(10)
del d[0]
del d[1]
del d[2]
del d[3]
del d[4]
del d[5]
d[0] = 3
d[1] = 4
d[2] = 5
d[3] = 3
d[4] = 4
d[5] = 5
x = d[0]
x = d[1]
x = d[2]
x = d[3]
x = d[4]
x = d[5]
has_key(0)
has_key(2)
has_key(4)
has_key(6)
has_key(8)
has_key(10)
del d[0]
del d[1]
del d[2]
del d[3]
del d[4]
del d[5]
d[0] = 3
d[1] = 4
d[2] = 5
d[3] = 3
d[4] = 4
d[5] = 5
x = d[0]
x = d[1]
x = d[2]
x = d[3]
x = d[4]
x = d[5]
has_key(0)
has_key(2)
has_key(4)
has_key(6)
has_key(8)
has_key(10)
del d[0]
del d[1]
del d[2]
del d[3]
del d[4]
del d[5]
d[0] = 3
d[1] = 4
d[2] = 5
d[3] = 3
d[4] = 4
d[5] = 5
x = d[0]
x = d[1]
x = d[2]
x = d[3]
x = d[4]
x = d[5]
has_key(0)
has_key(2)
has_key(4)
has_key(6)
has_key(8)
has_key(10)
del d[0]
del d[1]
del d[2]
del d[3]
del d[4]
del d[5]
def calibrate(self):
d = {}
has_key = d.has_key
for i in xrange(self.rounds):
pass
This diff is collapsed.
from pybench import Test
# First imports:
import os
import package.submodule
class SecondImport(Test):
version = 2.0
operations = 5 * 5
rounds = 40000
def test(self):
for i in xrange(self.rounds):
import os
import os
import os
import os
import os
import os
import os
import os
import os
import os
import os
import os
import os
import os
import os
import os
import os
import os
import os
import os
import os
import os
import os
import os
import os
def calibrate(self):
for i in xrange(self.rounds):
pass
class SecondPackageImport(Test):
version = 2.0
operations = 5 * 5
rounds = 40000
def test(self):
for i in xrange(self.rounds):
import package
import package
import package
import package
import package
import package
import package
import package
import package
import package
import package
import package
import package
import package
import package
import package
import package
import package
import package
import package
import package
import package
import package
import package
import package
def calibrate(self):
for i in xrange(self.rounds):
pass
class SecondSubmoduleImport(Test):
version = 2.0
operations = 5 * 5
rounds = 40000
def test(self):
for i in xrange(self.rounds):
import package.submodule
import package.submodule
import package.submodule
import package.submodule
import package.submodule
import package.submodule
import package.submodule
import package.submodule
import package.submodule
import package.submodule
import package.submodule
import package.submodule
import package.submodule
import package.submodule
import package.submodule
import package.submodule
import package.submodule
import package.submodule
import package.submodule
import package.submodule
import package.submodule
import package.submodule
import package.submodule
import package.submodule
import package.submodule
def calibrate(self):
for i in xrange(self.rounds):
pass
from pybench import Test
class CreateInstances(Test):
version = 2.0
operations = 3 + 7 + 4
rounds = 80000
def test(self):
class c:
pass
class d:
def __init__(self,a,b,c):
self.a = a
self.b = b
self.c = c
class e:
def __init__(self,a,b,c=4):
self.a = a
self.b = b
self.c = c
self.d = a
self.e = b
self.f = c
for i in xrange(self.rounds):
o = c()
o1 = c()
o2 = c()
p = d(i,i,3)
p1 = d(i,i,3)
p2 = d(i,3,3)
p3 = d(3,i,3)
p4 = d(i,i,i)
p5 = d(3,i,3)
p6 = d(i,i,i)
q = e(i,i,3)
q1 = e(i,i,3)
q2 = e(i,i,3)
q3 = e(i,i)
def calibrate(self):
class c:
pass
class d:
def __init__(self,a,b,c):
self.a = a
self.b = b
self.c = c
class e:
def __init__(self,a,b,c=4):
self.a = a
self.b = b
self.c = c
self.d = a
self.e = b
self.f = c
for i in xrange(self.rounds):
pass
pybench License
---------------
This copyright notice and license applies to all files in the pybench
directory of the pybench distribution.
Copyright (c), 1997-2006, Marc-Andre Lemburg (mal@lemburg.com)
Copyright (c), 2000-2006, eGenix.com Software GmbH (info@egenix.com)
All Rights Reserved.
Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee or royalty is hereby
granted, provided that the above copyright notice appear in all copies
and that both that copyright notice and this permission notice appear
in supporting documentation or portions thereof, including
modifications, that you make.
THE AUTHOR MARC-ANDRE LEMBURG DISCLAIMS ALL WARRANTIES WITH REGARD TO
THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS, IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL,
INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
WITH THE USE OR PERFORMANCE OF THIS SOFTWARE !
from pybench import Test
class SimpleListManipulation(Test):
version = 2.0
operations = 5* (6 + 6 + 6)
rounds = 130000
def test(self):
l = []
append = l.append
for i in xrange(self.rounds):
append(2)
append(3)
append(4)
append(2)
append(3)
append(4)
l[0] = 3
l[1] = 4
l[2] = 5
l[3] = 3
l[4] = 4
l[5] = 5
x = l[0]
x = l[1]
x = l[2]
x = l[3]
x = l[4]
x = l[5]
append(2)
append(3)
append(4)
append(2)
append(3)
append(4)
l[0] = 3
l[1] = 4
l[2] = 5
l[3] = 3
l[4] = 4
l[5] = 5
x = l[0]
x = l[1]
x = l[2]
x = l[3]
x = l[4]
x = l[5]
append(2)
append(3)
append(4)
append(2)
append(3)
append(4)
l[0] = 3
l[1] = 4
l[2] = 5
l[3] = 3
l[4] = 4
l[5] = 5
x = l[0]
x = l[1]
x = l[2]
x = l[3]
x = l[4]
x = l[5]
append(2)
append(3)
append(4)
append(2)
append(3)
append(4)
l[0] = 3
l[1] = 4
l[2] = 5
l[3] = 3
l[4] = 4
l[5] = 5
x = l[0]
x = l[1]
x = l[2]
x = l[3]
x = l[4]
x = l[5]
append(2)
append(3)
append(4)
append(2)
append(3)
append(4)
l[0] = 3
l[1] = 4
l[2] = 5
l[3] = 3
l[4] = 4
l[5] = 5
x = l[0]
x = l[1]
x = l[2]
x = l[3]
x = l[4]
x = l[5]
if len(l) > 10000:
# cut down the size
del l[:]
def calibrate(self):
l = []
append = l.append
for i in xrange(self.rounds):
pass
class ListSlicing(Test):
version = 2.0
operations = 25*(3+1+2+1)
rounds = 800
def test(self):
n = range(100)
r = range(25)
for i in xrange(self.rounds):
l = n[:]
for j in r:
m = l[50:]
m = l[:25]
m = l[50:55]
l[:3] = n
m = l[:-1]
m = l[1:]
l[-1:] = n
def calibrate(self):
n = range(100)
r = range(25)
for i in xrange(self.rounds):
for j in r:
pass
class SmallLists(Test):
version = 2.0
operations = 5*(1+ 6 + 6 + 3 + 1)
rounds = 80000
def test(self):
for i in xrange(self.rounds):
l = []
append = l.append
append(2)
append(3)
append(4)
append(2)
append(3)
append(4)
l[0] = 3
l[1] = 4
l[2] = 5
l[3] = 3
l[4] = 4
l[5] = 5
l[:3] = [1,2,3]
m = l[:-1]
m = l[1:]
l[-1:] = [4,5,6]
l = []
append = l.append
append(2)
append(3)
append(4)
append(2)
append(3)
append(4)
l[0] = 3
l[1] = 4
l[2] = 5
l[3] = 3
l[4] = 4
l[5] = 5
l[:3] = [1,2,3]
m = l[:-1]
m = l[1:]
l[-1:] = [4,5,6]
l = []
append = l.append
append(2)
append(3)
append(4)
append(2)
append(3)
append(4)
l[0] = 3
l[1] = 4
l[2] = 5
l[3] = 3
l[4] = 4
l[5] = 5
l[:3] = [1,2,3]
m = l[:-1]
m = l[1:]
l[-1:] = [4,5,6]
l = []
append = l.append
append(2)
append(3)
append(4)
append(2)
append(3)
append(4)
l[0] = 3
l[1] = 4
l[2] = 5
l[3] = 3
l[4] = 4
l[5] = 5
l[:3] = [1,2,3]
m = l[:-1]
m = l[1:]
l[-1:] = [4,5,6]
l = []
append = l.append
append(2)
append(3)
append(4)
append(2)
append(3)
append(4)
l[0] = 3
l[1] = 4
l[2] = 5
l[3] = 3
l[4] = 4
l[5] = 5
l[:3] = [1,2,3]
m = l[:-1]
m = l[1:]
l[-1:] = [4,5,6]
def calibrate(self):
for i in xrange(self.rounds):
pass
This diff is collapsed.
from pybench import Test
# Check for new-style class support:
try:
class c(object):
pass
except NameError:
raise ImportError
###
class CreateNewInstances(Test):
version = 2.0
operations = 3 + 7 + 4
rounds = 60000
def test(self):
class c(object):
pass
class d(object):
def __init__(self,a,b,c):
self.a = a
self.b = b
self.c = c
class e(object):
def __init__(self,a,b,c=4):
self.a = a
self.b = b
self.c = c
self.d = a
self.e = b
self.f = c
for i in xrange(self.rounds):
o = c()
o1 = c()
o2 = c()
p = d(i,i,3)
p1 = d(i,i,3)
p2 = d(i,3,3)
p3 = d(3,i,3)
p4 = d(i,i,i)
p5 = d(3,i,3)
p6 = d(i,i,i)
q = e(i,i,3)
q1 = e(i,i,3)
q2 = e(i,i,3)
q3 = e(i,i)
def calibrate(self):
class c(object):
pass
class d(object):
def __init__(self,a,b,c):
self.a = a
self.b = b
self.c = c
class e(object):
def __init__(self,a,b,c=4):
self.a = a
self.b = b
self.c = c
self.d = a
self.e = b
self.f = c
for i in xrange(self.rounds):
pass
This diff is collapsed.
This diff is collapsed.
#!python
# Setup file for pybench
#
# This file has to import all tests to be run; it is executed as
# Python source file, so you can do all kinds of manipulations here
# rather than having to edit the tests themselves.
#
# Note: Please keep this module compatible to Python 1.5.2.
#
# Tests may include features in later Python versions, but these
# should then be embedded in try-except clauses in this configuration
# module.
# Defaults
Number_of_rounds = 10
Warp_factor = 10
# Import tests
from Arithmetic import *
from Calls import *
from Constructs import *
from Lookups import *
from Instances import *
try:
from NewInstances import *
except ImportError:
pass
from Lists import *
from Tuples import *
from Dict import *
from Exceptions import *
from Imports import *
from Strings import *
from Numbers import *
try:
from Unicode import *
except (ImportError, SyntaxError):
pass
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
#!/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.
This diff is collapsed.
#!/usr/bin/env python
""" systimes() user and system timer implementations for use by
pybench.
This module implements various different strategies for measuring
performance timings. It tries to choose the best available method
based on the platforma and available tools.
On Windows, it is recommended to have the Mark Hammond win32
package installed. Alternatively, the Thomas Heller ctypes
packages can also be used.
On Unix systems, the standard resource module provides the highest
resolution timings. Unfortunately, it is not available on all Unix
platforms.
If no supported timing methods based on process time can be found,
the module reverts to the highest resolution wall-clock timer
instead. The system time part will then always be 0.0.
The module exports one public API:
def systimes():
Return the current timer values for measuring user and system
time as tuple of seconds (user_time, system_time).
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, sys, struct
#
# Note: Please keep this module compatible to Python 1.5.2.
#
# TODOs:
#
# * Add ctypes wrapper for new clock_gettime() real-time POSIX APIs;
# these will then provide nano-second resolution where available.
#
# * Add a function that returns the resolution of systimes()
# values, ie. systimesres().
#
### Choose an implementation
SYSTIMES_IMPLEMENTATION = None
USE_CTYPES_GETPROCESSTIMES = 'cytpes GetProcessTimes() wrapper'
USE_WIN32PROCESS_GETPROCESSTIMES = 'win32process.GetProcessTimes()'
USE_RESOURCE_GETRUSAGE = 'resource.getrusage()'
USE_PROCESS_TIME_CLOCK = 'time.clock() (process time)'
USE_WALL_TIME_CLOCK = 'time.clock() (wall-clock)'
USE_WALL_TIME_TIME = 'time.time() (wall-clock)'
if sys.platform[:3] == 'win':
# Windows platform
try:
import win32process
except ImportError:
try:
import ctypes
except ImportError:
# Use the wall-clock implementation time.clock(), since this
# is the highest resolution clock available on Windows
SYSTIMES_IMPLEMENTATION = USE_WALL_TIME_CLOCK
else:
SYSTIMES_IMPLEMENTATION = USE_CTYPES_GETPROCESSTIMES
else:
SYSTIMES_IMPLEMENTATION = USE_WIN32PROCESS_GETPROCESSTIMES
else:
# All other platforms
try:
import resource
except ImportError:
pass
else:
SYSTIMES_IMPLEMENTATION = USE_RESOURCE_GETRUSAGE
# Fall-back solution
if SYSTIMES_IMPLEMENTATION is None:
# Check whether we can use time.clock() as approximation
# for systimes()
start = time.clock()
time.sleep(0.1)
stop = time.clock()
if stop - start < 0.001:
# Looks like time.clock() is usable (and measures process
# time)
SYSTIMES_IMPLEMENTATION = USE_PROCESS_TIME_CLOCK
else:
# Use wall-clock implementation time.time() since this provides
# the highest resolution clock on most systems
SYSTIMES_IMPLEMENTATION = USE_WALL_TIME_TIME
### Implementations
def getrusage_systimes():
return resource.getrusage(resource.RUSAGE_SELF)[:2]
def process_time_clock_systimes():
return (time.clock(), 0.0)
def wall_clock_clock_systimes():
return (time.clock(), 0.0)
def wall_clock_time_systimes():
return (time.time(), 0.0)
# Number of clock ticks per second for the values returned
# by GetProcessTimes() on Windows.
#
# Note: Ticks returned by GetProcessTimes() are 100ns intervals on
# Windows XP. However, the process times are only updated with every
# 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():
d = win32process.GetProcessTimes(win32process.GetCurrentProcess())
return (d['UserTime'] / WIN32_PROCESS_TIMES_TICKS_PER_SECOND,
d['KernelTime'] / WIN32_PROCESS_TIMES_TICKS_PER_SECOND)
def ctypes_getprocesstimes_systimes():
creationtime = ctypes.c_ulonglong()
exittime = ctypes.c_ulonglong()
kerneltime = ctypes.c_ulonglong()
usertime = ctypes.c_ulonglong()
rc = ctypes.windll.kernel32.GetProcessTimes(
ctypes.windll.kernel32.GetCurrentProcess(),
ctypes.byref(creationtime),
ctypes.byref(exittime),
ctypes.byref(kerneltime),
ctypes.byref(usertime))
if not rc:
raise TypeError('GetProcessTimes() returned an error')
return (usertime.value / WIN32_PROCESS_TIMES_TICKS_PER_SECOND,
kerneltime.value / WIN32_PROCESS_TIMES_TICKS_PER_SECOND)
# Select the default for the systimes() function
if SYSTIMES_IMPLEMENTATION is USE_RESOURCE_GETRUSAGE:
systimes = getrusage_systimes
elif SYSTIMES_IMPLEMENTATION is USE_PROCESS_TIME_CLOCK:
systimes = process_time_clock_systimes
elif SYSTIMES_IMPLEMENTATION is USE_WALL_TIME_CLOCK:
systimes = wall_clock_clock_systimes
elif SYSTIMES_IMPLEMENTATION is USE_WALL_TIME_TIME:
systimes = wall_clock_time_systimes
elif SYSTIMES_IMPLEMENTATION is USE_WIN32PROCESS_GETPROCESSTIMES:
systimes = win32process_getprocesstimes_systimes
elif SYSTIMES_IMPLEMENTATION is USE_CTYPES_GETPROCESSTIMES:
systimes = ctypes_getprocesstimes_systimes
else:
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
def some_workload():
x = 0L
for i in xrange(10000000L):
x = x + 1L
def test_workload():
print 'Testing systimes() under load conditions'
t0 = systimes()
some_workload()
t1 = systimes()
print 'before:', t0
print 'after:', t1
print 'differences:', (t1[0] - t0[0], t1[1] - t0[1])
print
def test_idle():
print 'Testing systimes() under idle conditions'
t0 = systimes()
time.sleep(1)
t1 = systimes()
print 'before:', t0
print 'after:', t1
print 'differences:', (t1[0] - t0[0], t1[1] - t0[1])
print
if __name__ == '__main__':
print 'Using %s as timer' % SYSTIMES_IMPLEMENTATION
print
test_workload()
test_idle()
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