WARNING! Access to this system is limited to authorised users only.
Unauthorised users may be subject to prosecution.
Unauthorised access to this system is a criminal offence under Australian law (Federal Crimes Act 1914 Part VIA)
It is a criminal offence to:
(1) Obtain access to data without authority. -Penalty 2 years imprisonment.
(2) Damage, delete, alter or insert data without authority. -Penalty 10 years imprisonment.
User activity is monitored and recorded. Anyone using this system expressly consents to such monitoring and recording.

To protect your data, the CISO officer has suggested users to enable 2FA as soon as possible.
Currently 2.2% of users enabled 2FA.

Commit ed581644 authored by John Zhang's avatar John Zhang
Browse files

refactor fibonacci out into files

parent 371fb8c7
...@@ -3,7 +3,7 @@ Performance comparison ...@@ -3,7 +3,7 @@ Performance comparison
""" """
from time import time from time import time
from tempfile import mkdtemp from tempfile import mkdtemp
import py, os import py, os, sys
import subprocess as subp import subprocess as subp
import ctypes import ctypes
...@@ -12,24 +12,29 @@ from rpython.config.translationoption import set_opt_level ...@@ -12,24 +12,29 @@ from rpython.config.translationoption import set_opt_level
from util import libext, preload_libmu from util import libext, preload_libmu
perf_target_dir = py.path.local(__file__).dirpath().join('perftarget')
CPYTHON = os.environ.get('CPYTHON', 'python') CPYTHON = os.environ.get('CPYTHON', 'python')
PYPY = os.environ.get('PYPY', 'pypy') PYPY = os.environ.get('PYPY', 'pypy')
RPYTHON = os.environ.get('RPYTHON', None) RPYTHON = os.environ.get('RPYTHON', None)
CC = os.environ.get('CC', 'clang') CC = os.environ.get('CC', 'clang')
perf_target_dir = py.path.local(__file__).join('perf_target')
def run(cmd): def run(cmd):
# print ' '.join(cmd) print ' '.join(cmd)
p = subp.Popen(cmd, stdout=subp.PIPE, stderr=subp.PIPE) p = subp.Popen(cmd, stdout=subp.PIPE, stderr=subp.PIPE)
return p.communicate() return p.communicate()
def get_c_function(lib, f): def get_c_function(lib, f):
from ctypes import CDLL from ctypes import CDLL
name = f.__name__ name = f.__name__
return getattr(CDLL(lib.strpath), 'pypy_g_' + name) return getattr(CDLL(lib.strpath), 'pypy_g_' + name)
def perf_fibonacci(): def perf_fibonacci():
from perftarget.fibonacci import fib
tmpdir = py.path.local(mkdtemp()) tmpdir = py.path.local(mkdtemp())
print tmpdir print tmpdir
...@@ -49,7 +54,6 @@ def perf_fibonacci(): ...@@ -49,7 +54,6 @@ def perf_fibonacci():
return float(out) return float(out)
def compile_rpython_c(): def compile_rpython_c():
from perf_target.fibonacci import fib
t = Translation(fib, [int], t = Translation(fib, [int],
gc='none') gc='none')
set_opt_level(t.config, '3') set_opt_level(t.config, '3')
...@@ -59,7 +63,6 @@ def perf_fibonacci(): ...@@ -59,7 +63,6 @@ def perf_fibonacci():
return fnp return fnp
def compile_rpython_c_jit(): def compile_rpython_c_jit():
from perf_target.fibonacci import fib
t = Translation(fib, [int], t = Translation(fib, [int],
gc='none') gc='none')
set_opt_level(t.config, 'jit') set_opt_level(t.config, 'jit')
...@@ -76,8 +79,6 @@ def perf_fibonacci(): ...@@ -76,8 +79,6 @@ def perf_fibonacci():
def compile_rpython_mu(): def compile_rpython_mu():
preload_libmu() preload_libmu()
from perf_target.fibonacci import fib
t = Translation(fib, [int], t = Translation(fib, [int],
backend='mu', muimpl='fast', mucodegen='api', mutestjit=True) backend='mu', muimpl='fast', mucodegen='api', mutestjit=True)
set_opt_level(t.config, '3') set_opt_level(t.config, '3')
...@@ -108,15 +109,16 @@ def perf_fibonacci(): ...@@ -108,15 +109,16 @@ def perf_fibonacci():
return get_average_time(lambda *a: run_funcptr(fnp, *a), args, warmup, iterations) return get_average_time(lambda *a: run_funcptr(fnp, *a), args, warmup, iterations)
N = 30 N = 30
iterations = 10 warmup = 0
iterations = 1
t_cpython = get_average_time(run_cpython, [N], iterations=iterations)
t_pypy_nojit = get_average_time(run_pypy_nojit, [N], iterations=iterations) t_cpython = get_average_time(run_cpython, [N], warmup, iterations=iterations)
t_pypy = get_average_time(run_pypy, [N], iterations=iterations) t_pypy_nojit = get_average_time(run_pypy_nojit, [N], warmup, iterations=iterations)
t_rpyc = get_average_time_compiled(compile_rpython_c, [N], iterations=iterations) t_pypy = get_average_time(run_pypy, [N], warmup, iterations=iterations)
t_rpyc_jit = get_average_time_compiled(compile_rpython_c_jit, [N], iterations=iterations) t_rpyc = get_average_time_compiled(compile_rpython_c, [N], warmup, iterations=iterations)
t_rpyc_mu = get_average_time_compiled(compile_rpython_mu, [N], iterations=iterations) t_rpyc_jit = get_average_time_compiled(compile_rpython_c_jit, [N], warmup, iterations=iterations)
t_c = get_average_time_compiled(compile_c, [N], iterations=iterations) t_rpyc_mu = get_average_time_compiled(compile_rpython_mu, [N], warmup, iterations=iterations)
t_c = get_average_time_compiled(compile_c, [N], warmup, iterations=iterations)
print "CPython:", t_cpython print "CPython:", t_cpython
print "PyPy (no JIT):", t_pypy_nojit print "PyPy (no JIT):", t_pypy_nojit
print "PyPy:", t_pypy print "PyPy:", t_pypy
......
...@@ -21,7 +21,7 @@ def rpy_entry(N): ...@@ -21,7 +21,7 @@ def rpy_entry(N):
if __name__ == '__main__': if __name__ == '__main__':
import sys import sys
t0, t1 = measure(int(sys.argv[1])) t0, t1 = measure(int(sys.argv[1]))
print '%.15df' % (t1 - t0) print '%.15f' % (t1 - t0)
def target(*args): def target(*args):
......
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