Commit d556f965 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Merge pull request #1008 from kmod/ubenchs

microbenchmarks for the presentation
parents 14aa0f0a f771d5a5
N = 1024
def f(n):
l = []
assert N % n == 0
while len(l) < N:
l += range(n)
t = 0
for _ in xrange(2000):
for i in l:
if i & 1: t += 1
else: t += 2
if i & 2: t += 1
else: t += 2
if i & 4: t += 1
else: t += 2
if i & 8: t += 1
else: t += 2
if i & 16: t += 1
else: t += 2
if i & 32: t += 1
else: t += 2
if i & 64: t += 1
else: t += 2
if i & 128: t += 1
else: t += 2
if i & 256: t += 1
else: t += 2
if i & 512: t += 1
else: t += 2
# print t
import sys
f(int(sys.argv[1]))
import os
import sys
sys.path.append(os.path.join(os.path.dirname(__file__), "../test/testsuite/lib/django"))
sys.path.append(os.path.join(os.path.dirname(__file__), "../test/lib/django"))
BENCHMARK_SUITE_DIR = os.path.join(os.path.dirname(__file__), "../../pyston-perf/benchmarking/benchmark_suite")
sys.path.extend([os.path.join(BENCHMARK_SUITE_DIR, "django_template2_site")])
......
M = 64
N = 64
def f(m, n):
assert N % n == 0
assert M % m == 0
l1 = []
for i in xrange(m):
class C(object):
pass
c = C()
c.x = i
l1.append(c)
lm = []
while len(lm) < M:
lm += l1
ln = []
while len(ln) < N:
ln += range(n)
t = 0
for _ in xrange(400):
for i in ln:
for o in lm:
if i & 1: t += o.x
else: t -= o.x
if i & 2: t += o.x
else: t -= o.x
if i & 4: t += o.x
else: t -= o.x
if i & 8: t += o.x
else: t -= o.x
if i & 16: t += o.x
else: t -= o.x
if i & 32: t += o.x
else: t -= o.x
if i & 64: t += o.x
else: t -= o.x
if i & 128: t += o.x
else: t -= o.x
if i & 256: t += o.x
else: t -= o.x
if i & 512: t += o.x
else: t -= o.x
# print t
import sys
f(int(sys.argv[1]), int(sys.argv[2]))
N = 1024
def f(n):
l = []
assert N % n == 0
l2 = []
for i in xrange(n):
class C(object):
pass
c = C()
c.x = i
l2.append(c)
while len(l) < N:
l += l2
t = 0
for _ in xrange(20000):
for o in l:
t += o.x
import sys
f(int(sys.argv[1]))
import os
import subprocess
import time
EXECUTABLES = [
'python',
os.path.join(os.path.dirname(__file__), '../pyston_pgo'),
os.path.join(os.path.dirname(__file__), '../../pyston_related/pypy-4.0.0-linux64/bin/pypy')
]
BENCHMARKS = [
os.path.join(os.path.dirname(__file__), 'megamorphic_control_flow.py')
]
ARGS = [[str(2**i), "16"] for i in xrange(0, 7)]
BENCHMARKS = [
os.path.join(os.path.dirname(__file__), 'control_flow_ubench.py'),
os.path.join(os.path.dirname(__file__), 'megamorphic_ubench.py')
]
ARGS = [[str(2**i)] for i in xrange(0, 10)]
NRUNS = 3
for b in BENCHMARKS:
print os.path.basename(b)
for args in ARGS:
print ' '.join(args)
for exe in EXECUTABLES:
print os.path.basename(exe)
for args in ARGS:
best = float('inf')
for _ in xrange(NRUNS):
start = time.time()
subprocess.check_call([exe, b] + args)
elapsed = time.time() - start
best = min(best, elapsed)
print best
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