本文整理汇总了Python中rpython.translator.tool.cbuild.ExternalCompilationInfo.separate_module_files方法的典型用法代码示例。如果您正苦于以下问题:Python ExternalCompilationInfo.separate_module_files方法的具体用法?Python ExternalCompilationInfo.separate_module_files怎么用?Python ExternalCompilationInfo.separate_module_files使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rpython.translator.tool.cbuild.ExternalCompilationInfo
的用法示例。
在下文中一共展示了ExternalCompilationInfo.separate_module_files方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_precompiled_headers
# 需要导入模块: from rpython.translator.tool.cbuild import ExternalCompilationInfo [as 别名]
# 或者: from rpython.translator.tool.cbuild.ExternalCompilationInfo import separate_module_files [as 别名]
def test_precompiled_headers(self):
if self.platform.cc != 'cl.exe':
py.test.skip("Only MSVC profits from precompiled headers")
import time
tmpdir = udir.join('precompiled_headers').ensure(dir=1)
# Create an eci that should not use precompiled headers
eci = ExternalCompilationInfo(include_dirs=[tmpdir])
main_c = tmpdir.join('main_no_pch.c')
eci.separate_module_files = [main_c]
ncfiles = 10
nprecompiled_headers = 20
txt = ''
for i in range(ncfiles):
txt += "int func%03d();\n" % i
txt += "\nint main(int argc, char * argv[])\n"
txt += "{\n int i=0;\n"
for i in range(ncfiles):
txt += " i += func%03d();\n" % i
txt += ' printf("%d\\n", i);\n'
txt += " return 0;\n};\n"
main_c.write(txt)
# Create some large headers with dummy functions to be precompiled
cfiles_precompiled_headers = []
for i in range(nprecompiled_headers):
pch_name =tmpdir.join('pcheader%03d.h' % i)
txt = '#ifndef PCHEADER%03d_H\n#define PCHEADER%03d_H\n' %(i, i)
for j in range(3000):
txt += "int pcfunc%03d_%03d();\n" %(i, j)
txt += '#endif'
pch_name.write(txt)
cfiles_precompiled_headers.append(pch_name)
# Create some cfiles with headers we want precompiled
cfiles = []
for i in range(ncfiles):
c_name =tmpdir.join('implement%03d.c' % i)
txt = ''
for pch_name in cfiles_precompiled_headers:
txt += '#include "%s"\n' % pch_name
txt += "int func%03d(){ return %d;};\n" % (i, i)
c_name.write(txt)
cfiles.append(c_name)
if sys.platform == 'win32':
clean = ('clean', '', 'for %f in ( $(OBJECTS) $(TARGET) ) do @if exist %f del /f %f')
get_time = time.clock
else:
clean = ('clean', '', 'rm -f $(OBJECTS) $(TARGET) ')
get_time = time.time
#write a non-precompiled header makefile
mk = self.platform.gen_makefile(cfiles, eci, path=tmpdir)
mk.rule(*clean)
mk.write()
t0 = get_time()
self.platform.execute_makefile(mk)
t1 = get_time()
t_normal = t1 - t0
self.platform.execute_makefile(mk, extra_opts=['clean'])
# Write a super-duper makefile with precompiled headers
mk = self.platform.gen_makefile(cfiles, eci, path=tmpdir,
headers_to_precompile=cfiles_precompiled_headers,)
mk.rule(*clean)
mk.write()
t0 = get_time()
self.platform.execute_makefile(mk)
t1 = get_time()
t_precompiled = t1 - t0
res = self.platform.execute(mk.exe_name)
self.check_res(res, '%d\n' %sum(range(ncfiles)))
print "precompiled haeder 'make' time %.2f, non-precompiled header time %.2f" %(t_precompiled, t_normal)
assert t_precompiled < t_normal * 0.5