本文整理汇总了Python中pypy.translator.interactive.Translation.compile方法的典型用法代码示例。如果您正苦于以下问题:Python Translation.compile方法的具体用法?Python Translation.compile怎么用?Python Translation.compile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pypy.translator.interactive.Translation
的用法示例。
在下文中一共展示了Translation.compile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_profopt
# 需要导入模块: from pypy.translator.interactive import Translation [as 别名]
# 或者: from pypy.translator.interactive.Translation import compile [as 别名]
def test_profopt():
if sys.platform == 'win32':
py.test.skip("instrumentation support is unix only for now")
def add(a,b):
return a + b - b + b - b + b - b + b - b + b - b + b - b + b
def entry_point(argv):
tot = 0
x = int(argv[1])
while x > 0:
tot = add(tot, x)
x -= 1
os.write(1, str(tot))
return 0
from pypy.translator.interactive import Translation
# XXX this is mostly a "does not crash option"
t = Translation(entry_point, backend='c', standalone=True, profopt="")
# no counters
t.backendopt()
exe = t.compile()
out = py.process.cmdexec("%s 500" % exe)
assert int(out) == 500*501/2
t = Translation(entry_point, backend='c', standalone=True, profopt="",
noprofopt=True)
# no counters
t.backendopt()
exe = t.compile()
out = py.process.cmdexec("%s 500" % exe)
assert int(out) == 500*501/2
示例2: main
# 需要导入模块: from pypy.translator.interactive import Translation [as 别名]
# 或者: from pypy.translator.interactive.Translation import compile [as 别名]
def main():
import_benchmarks()
benchmarks = []
for name, thing in globals().iteritems():
if getattr(thing, 'benchmark', False):
benchmarks.append((name, thing))
benchmarks.sort()
def entry_point(argv):
for name, func in benchmarks:
print name, ':', func()
return 0
t = Translation(entry_point, standalone=True, backend='c')
c_exe = t.compile()
t = Translation(entry_point, standalone=True, backend='cli')
cli_exe = t.compile()
c_res = run_benchmark(c_exe)
cli_res = run_benchmark(cli_exe)
print 'benchmark genc gencli ratio'
print
for name, _ in benchmarks:
c_time = c_res[name]
cli_time = cli_res[name]
if c_time == 0:
ratio = '%10s' % '---'
else:
ratio = '%10.2f' % (cli_time/c_time)
print '%-32s %10.2f %10.2f %s' % (name, c_time, cli_time, ratio)
示例3: test_profopt
# 需要导入模块: from pypy.translator.interactive import Translation [as 别名]
# 或者: from pypy.translator.interactive.Translation import compile [as 别名]
def test_profopt(self):
def add(a,b):
return a + b - b + b - b + b - b + b - b + b - b + b - b + b
def entry_point(argv):
tot = 0
x = int(argv[1])
while x > 0:
tot = add(tot, x)
x -= 1
os.write(1, str(tot))
return 0
from pypy.translator.interactive import Translation
# XXX this is mostly a "does not crash option"
t = Translation(entry_point, backend='c', standalone=True, profopt="100")
# no counters
t.backendopt()
exe = t.compile()
out = py.process.cmdexec("%s 500" % exe)
assert int(out) == 500*501/2
t = Translation(entry_point, backend='c', standalone=True, profopt="100",
noprofopt=True)
# no counters
t.backendopt()
exe = t.compile()
out = py.process.cmdexec("%s 500" % exe)
assert int(out) == 500*501/2
示例4: test_prof_inline
# 需要导入模块: from pypy.translator.interactive import Translation [as 别名]
# 或者: from pypy.translator.interactive.Translation import compile [as 别名]
def test_prof_inline():
if sys.platform == 'win32':
py.test.skip("instrumentation support is unix only for now")
def add(a,b):
return a + b - b + b - b + b - b + b - b + b - b + b - b + b
def entry_point(argv):
tot = 0
x = int(argv[1])
while x > 0:
tot = add(tot, x)
x -= 1
os.write(1, str(tot))
return 0
from pypy.translator.interactive import Translation
t = Translation(entry_point, backend='c', standalone=True)
# no counters
t.backendopt(inline_threshold=100, profile_based_inline="500")
exe = t.compile()
out = py.process.cmdexec("%s 500" % exe)
assert int(out) == 500*501/2
t = Translation(entry_point, backend='c', standalone=True)
# counters
t.backendopt(inline_threshold=all.INLINE_THRESHOLD_FOR_TEST*0.5,
profile_based_inline="500")
exe = t.compile()
out = py.process.cmdexec("%s 500" % exe)
assert int(out) == 500*501/2
示例5: _makefunc_str_int
# 需要导入模块: from pypy.translator.interactive import Translation [as 别名]
# 或者: from pypy.translator.interactive.Translation import compile [as 别名]
def _makefunc_str_int(cls, f):
def main(argv):
arg0 = argv[1]
arg1 = int(argv[2])
try:
res = f(arg0, arg1)
except MemoryError:
print "MEMORY-ERROR"
else:
print res
return 0
t = Translation(main, standalone=True, gc=cls.gcpolicy,
policy=annpolicy.StrictAnnotatorPolicy(),
taggedpointers=cls.taggedpointers,
gcremovetypeptr=cls.removetypeptr)
t.disable(['backendopt'])
t.set_backend_extra_options(c_debug_defines=True)
t.rtype()
if conftest.option.view:
t.viewcg()
exename = t.compile()
def run(s, i):
data = py.process.cmdexec("%s %s %d" % (exename, s, i))
data = data.strip()
if data == 'MEMORY-ERROR':
raise MemoryError
return data
return run
示例6: test_lib
# 需要导入模块: from pypy.translator.interactive import Translation [as 别名]
# 或者: from pypy.translator.interactive.Translation import compile [as 别名]
def test_lib():
def entry_point(argv):
fd = os.open("/tmp/foobar", os.O_RDONLY, 0777)
assert fd == 77
res = os.read(fd, 123)
assert res == "he\x00llo"
count = os.write(fd, "world\x00!\x00")
assert count == 42
for arg in argv:
count = os.write(fd, arg)
assert count == 61
os.close(fd)
return 0
t = Translation(entry_point, backend='c', standalone=True, sandbox=True)
exe = t.compile()
proc = MySandboxedProc([exe, 'x1', 'y2'], expected = [
("open", ("/tmp/foobar", os.O_RDONLY, 0777), 77),
("read", (77, 123), "he\x00llo"),
("write", (77, "world\x00!\x00"), 42),
("write", (77, exe), 61),
("write", (77, "x1"), 61),
("write", (77, "y2"), 61),
("close", (77,), None),
])
proc.handle_forever()
assert proc.seen == len(proc.expected)
示例7: run
# 需要导入模块: from pypy.translator.interactive import Translation [as 别名]
# 或者: from pypy.translator.interactive.Translation import compile [as 别名]
def run(self, entry_point, args, expected):
t = Translation(entry_point, backend='c', standalone=True,
sandbox=True)
exe = t.compile()
from pypy.translator.sandbox.sandlib import SimpleIOSandboxedProc
proc = SimpleIOSandboxedProc([exe] + args)
output, error = proc.communicate()
assert error == ''
assert output == expected
示例8: main
# 需要导入模块: from pypy.translator.interactive import Translation [as 别名]
# 或者: from pypy.translator.interactive.Translation import compile [as 别名]
def main():
import_benchmarks()
benchmarks = []
for name, thing in globals().iteritems():
if getattr(thing, "benchmark", False):
benchmarks.append((name, thing))
benchmarks.sort()
def entry_point(argv):
for name, func in benchmarks:
print name, ":", func()
return 0
t = Translation(entry_point, standalone=True, backend="c")
c_exe = t.compile()
t = Translation(entry_point, standalone=True, backend="cli")
cli_exe = t.compile()
t = Translation(entry_point, standalone=True, backend="jvm")
jvm_exe = t.compile()
c_res = run_benchmark(c_exe)
cli_res = run_benchmark(cli_exe)
jvm_res = run_benchmark(jvm_exe)
print "benchmark genc gencli cli_ratio genjvm jvm_ratio"
print
for name, _ in benchmarks:
c_time = c_res[name]
cli_time = cli_res[name]
jvm_time = jvm_res[name]
if c_time == 0:
cli_ratio = "%10s" % "---"
else:
cli_ratio = "%10.2f" % (cli_time / c_time)
if c_time == 0:
jvm_ratio = "%10s" % "---"
else:
jvm_ratio = "%10.2f" % (jvm_time / c_time)
print "%-32s %10.2f %10.2f %s %10.2f %s" % (name, c_time, cli_time, cli_ratio, jvm_time, jvm_ratio)
示例9: test_profopt_mac_osx_bug
# 需要导入模块: from pypy.translator.interactive import Translation [as 别名]
# 或者: from pypy.translator.interactive.Translation import compile [as 别名]
def test_profopt_mac_osx_bug(self):
if sys.platform == 'win32':
py.test.skip("no profopt on win32")
def entry_point(argv):
import os
pid = os.fork()
if pid:
os.waitpid(pid, 0)
else:
os._exit(0)
return 0
from pypy.translator.interactive import Translation
# XXX this is mostly a "does not crash option"
t = Translation(entry_point, backend='c', standalone=True, profopt="")
# no counters
t.backendopt()
exe = t.compile()
#py.process.cmdexec(exe)
t = Translation(entry_point, backend='c', standalone=True, profopt="",
noprofopt=True)
# no counters
t.backendopt()
exe = t.compile()
示例10: test_dup2_access
# 需要导入模块: from pypy.translator.interactive import Translation [as 别名]
# 或者: from pypy.translator.interactive.Translation import compile [as 别名]
def test_dup2_access():
def entry_point(argv):
os.dup2(34, 56)
y = os.access("spam", 77)
return 1 - y
t = Translation(entry_point, backend='c', standalone=True, sandbox=True)
exe = t.compile()
g, f = os.popen2(exe, "t", 0)
expect(f, g, "ll_os.ll_os_dup2", (34, 56), None)
expect(f, g, "ll_os.ll_os_access", ("spam", 77), True)
g.close()
tail = f.read()
f.close()
assert tail == ""
示例11: test_time
# 需要导入模块: from pypy.translator.interactive import Translation [as 别名]
# 或者: from pypy.translator.interactive.Translation import compile [as 别名]
def test_time():
def entry_point(argv):
t = time.time()
os.dup(int(t*1000))
return 0
t = Translation(entry_point, backend='c', standalone=True, sandbox=True)
exe = t.compile()
g, f = os.popen2(exe, "t", 0)
expect(f, g, "ll_time.ll_time_time", (), 3.141592)
expect(f, g, "ll_os.ll_os_dup", (3141,), 3)
g.close()
tail = f.read()
f.close()
assert tail == ""
示例12: test_foobar
# 需要导入模块: from pypy.translator.interactive import Translation [as 别名]
# 或者: from pypy.translator.interactive.Translation import compile [as 别名]
def test_foobar():
py.test.skip("to be updated")
foobar = rffi.llexternal("foobar", [rffi.CCHARP], rffi.LONG)
def entry_point(argv):
s = rffi.str2charp(argv[1]); n = foobar(s); rffi.free_charp(s)
s = rffi.str2charp(argv[n]); n = foobar(s); rffi.free_charp(s)
return n
t = Translation(entry_point, backend='c', standalone=True, sandbox=True)
exe = t.compile()
proc = MySandboxedProc([exe, 'spam', 'egg'], expected = [
("foobar", ("spam",), 2),
("foobar", ("egg",), 0),
])
proc.handle_forever()
assert proc.seen == len(proc.expected)
示例13: test_simple_compile_c
# 需要导入模块: from pypy.translator.interactive import Translation [as 别名]
# 或者: from pypy.translator.interactive.Translation import compile [as 别名]
def test_simple_compile_c():
def f(x,y):
return x+y
t = Translation(f, [int, int])
t.source(backend='c')
t_f = t.compile()
res = t_f(2,3)
assert res == 5
t = Translation(f, [int, int])
t_f = t.compile_c()
res = t_f(2,3)
assert res == 5
示例14: test_open_dup
# 需要导入模块: from pypy.translator.interactive import Translation [as 别名]
# 或者: from pypy.translator.interactive.Translation import compile [as 别名]
def test_open_dup():
def entry_point(argv):
fd = os.open("/tmp/foobar", os.O_RDONLY, 0777)
assert fd == 77
fd2 = os.dup(fd)
assert fd2 == 78
return 0
t = Translation(entry_point, backend='c', standalone=True, sandbox=True)
exe = t.compile()
g, f = os.popen2(exe, "t", 0)
expect(f, g, "ll_os.ll_os_open", ("/tmp/foobar", os.O_RDONLY, 0777), 77)
expect(f, g, "ll_os.ll_os_dup", (77,), 78)
g.close()
tail = f.read()
f.close()
assert tail == ""
示例15: test_stat_ftruncate
# 需要导入模块: from pypy.translator.interactive import Translation [as 别名]
# 或者: from pypy.translator.interactive.Translation import compile [as 别名]
def test_stat_ftruncate():
from pypy.rpython.module.ll_os_stat import s_StatResult
from pypy.rlib.rarithmetic import r_longlong
r0x12380000007 = r_longlong(0x12380000007)
def entry_point(argv):
st = os.stat("somewhere")
os.ftruncate(st.st_mode, st.st_size) # nonsense, just to see outside
return 0
t = Translation(entry_point, backend='c', standalone=True, sandbox=True)
exe = t.compile()
g, f = os.popen2(exe, "t", 0)
st = os.stat_result((55, 0, 0, 0, 0, 0, 0x12380000007, 0, 0, 0))
expect(f, g, "ll_os.ll_os_stat", ("somewhere",), st,
resulttype = s_StatResult)
expect(f, g, "ll_os.ll_os_ftruncate", (55, 0x12380000007), None)
g.close()
tail = f.read()
f.close()
assert tail == ""